﻿'''''Prachak Nov 25, 2014 09.00
Imports System.Data
Imports System.Data.OleDb
Imports ADOEntityKYC
Partial Class KYC_IndividualCDD
    Inherits Web.UI.BasePage

#Region " Variable Gobal "

    Dim ds As DataSet
    Dim clsRiskLevel As clsRiskLevel = New clsRiskLevel
    Dim cn As New OleDbConnection
    Dim KYCEntity As KYCEntities = New KYCEntities
    Dim clsSessionMenuRight As clsSessionMenuRight = New clsSessionMenuRight
    Dim TypeKYC As Integer = 0  ' 1--> ลูกค้าใหม่ , 2-->ลูกค้าเก่า
    Dim CustSeq As Integer = 0
    Dim clsCheckLanguage As clsCheckLanguage
    Dim clsCheckID As clsCheckID
    Dim strMsg As String = ""
    Dim convertDate As clsDateFormat
    Dim clsDataTable As clsLINQToDataTable

    ''''''''' Prachak ''''''''''''''''''''''
    Dim clsDatabase As clsDatabase
    Dim clsValid As clsValidateData
    Dim lvsSQL As String
    Dim dtAddedService As New DataTable
    Dim dtProduct As New DataTable
    Dim dtPassport As New DataTable
    Dim dtOtherID As New DataTable
    Dim dtNation As New DataTable
    Dim dtSanc As New DataTable
    Dim dtOcc As New DataTable
    Dim dtIncome As New DataTable
    Dim dtReason As New DataTable
    Dim dtFamily As New DataTable
    Dim dtPolitical As New DataTable
    Dim dtBo As New DataTable
    Dim dtCustName As New DataTable
    Dim intBeforeItemIndex As Integer
    Dim intBeforeSelectIndex_grdNaiton As Integer
    Dim intBeforeSelectIndex_OTHER As Integer
    Dim intBeforeSelectIndex_Passport As Integer
    Dim intBeforeSelectIndex_Politician As Integer
    Dim intBeforeSelectIndex_Occ As Integer
    Dim intBeforeSelectIndex_Income As Integer
    Dim intBeforeSelectIndex_BO As Integer
    Dim intBeforeSelectIndex_Family As Integer
    Dim intBeforeSelectIndex_Reason As Integer
    Dim intBeforeSelectIndex_Product As Integer
    Dim intBeforeSelectIndex_AddedService As Integer


    Private Enum enmStatusNewAcc
        NoHaveNewAcc = 0
        HaveNewAcc = 1

    End Enum

#End Region

#Region "Even Page"

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        clsValid = New clsValidateData()
        clsDatabase = New clsDatabase

        Try

            ''''''''Prachak ''''''''''''''''''''''''''''
            If (Session("PopCustName") Is Nothing) Then
                Me.grdCust_NAME.DataSource = dtCustName
                Me.grdCust_NAME.DataBind()
            End If

            If (Session("PopPassport") Is Nothing) Then
                grdPassport.DataSource = dtPassport
                grdPassport.DataBind()
            End If

            If (Session("PopOtherID") Is Nothing) Then
                grdOtherID.DataSource = dtOtherID
                grdOtherID.DataBind()
            End If

            If (Session("PopNation") Is Nothing) Then
                grdNaiton.DataSource = dtNation
                grdNaiton.DataBind()
            End If

            If (Session("PopSanc") Is Nothing) Then
                grdSanc.DataSource = dtSanc
                grdSanc.DataBind()
            End If

            'If (Session("Sanction") Is Nothing) Then
            '    grdSanc.DataSource = dtSanc
            '    grdSanc.DataBind()
            'End If

            If (Session("PopOcc") Is Nothing) Then
                grdOcc.DataSource = dtOcc
                grdOcc.DataBind()
            End If

            If (Session("PopINCOME") Is Nothing) Then
                grdIncome.DataSource = dtIncome
                grdIncome.DataBind()
            End If

            If (Session("PopReason") Is Nothing) Then
                grdReason.DataSource = dtReason
                grdReason.DataBind()
            End If

            If (Session("PopFamily") Is Nothing) Then
                grdFamily.DataSource = dtFamily
                grdFamily.DataBind()
            End If

            If (Session("PopPolitical") Is Nothing) Then
                grdPolitical.DataSource = dtPolitical
                grdPolitical.DataBind()
            End If

            If (Session("PopBo") Is Nothing) Then
                grdBo.DataSource = dtBo
                grdBo.DataBind()
            End If

            ''''Prachak''
            Me.SetControl_Enable()
            ''''''''''''''''''

            ds = Session("ds")
            clsSessionMenuRight = Session("clsMenuRight")

            '''''ตรวจกรองรายชื่อ '''''''''''''''''''''''''''''
            Me.btnFilter_CUST.Attributes.Add("onclick", "NoDoubleSubmit(); setAmlistParam(); popAMListWindow();")
            Me.btnFilter_PASSPORT.Attributes.Add("onclick", "NoDoubleSubmit(); setAmlistParam_Passport(); popAMListWindow();")
            Me.btnFilter_BO.Attributes.Add("onclick", "NoDoubleSubmit(); setAmlistParam_BO(); popAMListWindow();")
            Me.btnFilter_Family.Attributes.Add("onclick", "NoDoubleSubmit(); setAmlistParam_FAMILY(); popAMListWindow();")

            If Not TypeKYC = 4 Then
                btnCancel.Attributes.Add("onclick", "return confirm('" + String.Format(Resources.resMsgKYC.msgCancle) + "')")
                btnKYCNext.Attributes.Add("onclick", "return confirm('" + String.Format(Resources.resMsgKYC.msgKYCNext) + "')")

            End If

            If Not IsPostBack Then

                ''''Prachak
                Me.Set_Family_Enable_False()
                ' ''''Prachak Oct 27, 2014 Enabled
                Me.PanelApprove.Enabled = False

                Session("TypeKYC") = Request.QueryString("TypeKYC")
                Session("CUSTSEQ") = Request.QueryString("CUSTSEQ")
                TypeKYC = Request.QueryString("TypeKYC")
                CustSeq = Request.QueryString("CUSTSEQ")

                chkIsLogin()
                CreateControlMP()
                loadDataToDropDown()

                txtSalaryPerMonth.Text = "0"
                txtSalaryPerMonth.Enabled = True
                rdoAnsSalary.SelectedValue = "1"
                rdoAcc.SelectedValue = "0"

                If TypeKYC = 1 Then
                    If Not Request.QueryString("Back") = "1" Then
                        AutoInput()
                    End If
                    ''''Prachak '''''''
                    Me.Find_SmartCard_for_Customer(Me.txtUniqueID.Text)
                    ''''Prachak '''''''

                    Me.Bind_Data_togrid_Passport()
                    Me.Bind_Data_togrid_grdOtherID()
                    Me.Bind_Data_togrid_CustName()
                    Me.Bind_Data_togrid_Nation()
                    Me.Bind_Data_togrid_Sanction()
                    Me.Bind_Data_togrid_grdPolitical()
                    Me.Bind_Data_togrid_grdOcc()
                    Me.Bind_Data_togrid_Income_Source()
                    Me.Bind_Data_togrid_BO()
                    Me.Bind_Data_togrid_Family()
                    Me.Bind_Data_togrid_Reason()
                    Me.Bind_Data_togrid_Product()
                    Me.Bind_Data_togrdAddedService()

                    ''''''''''''''''''''''''''''''

                    lblRiskNow.Visible = False
                    btnKYC.Visible = False
                    btnHistory.Visible = False

                ElseIf TypeKYC = 2 Then
                    btnHistory.Visible = True
                    BindingData()
                    BindingAcc(CustSeq)
                    indexBizChanging1()
                    indexBizChanging2()
                    indexBizChanging3()
                    indexOccupationChanging1()
                    indexOccupationChanging2()
                    indexOccupationChanging3()
                    If hdfApprCode_MCus.Value = "1" Then
                        btnCompile.Visible = False
                        btnEditCompile.Visible = False
                        lblTextMsg.Visible = False
                    End If

                    ''''Prachak '''''''
                    Me.Bind_Data_togrid_Passport()
                    Me.Bind_Data_togrid_grdOtherID()
                    Me.Bind_Data_togrid_CustName()
                    Me.Bind_Data_togrid_Nation()
                    Me.Bind_Data_togrid_Sanction()
                    Me.Bind_Data_togrid_grdPolitical()
                    Me.Bind_Data_togrid_grdOcc()
                    Me.Bind_Data_togrid_Income_Source()
                    Me.Bind_Data_togrid_BO()
                    Me.Bind_Data_togrid_Family()
                    Me.Bind_Data_togrid_Reason()
                    Me.Bind_Data_togrid_Product()
                    Me.Bind_Data_togrdAddedService()
                    ''''''''''''''''''''''''''''''

                End If


                'If Not hdfApprCode_MCus.Value = "" Then
                '    If Not hdfApprCode_MCus.Value = 0 Then
                '        ScriptManager.RegisterStartupScript(UpdatePanel1, _
                '                                              UpdatePanel1.GetType(), _
                '                                              "clientScript", _
                '                                              "alert('" + "เนื่องจากติดการอนุมัติ กรุณาทำการอนุมัติก่อน" + "')", _
                '                                              True)
                '    End If
                'End If

            Else
                TypeKYC = Session("TypeKYC")
                CustSeq = Session("CUSTSEQ")


            End If
            If Session("KYC") = "2" Or Session("KYC") = "5" Then
                rdoAcc.SelectedValue = "1"
                rdoAcc.Enabled = False
            End If
            If Session("KYC") = "5" And TypeKYC = 1 Then
                ddlTranType.SelectedValue = "2"

            End If


        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1,
                                                UpdatePanel1.GetType(),
                                                "clientScript",
                                                "alert('" + ex.Message.Replace("'", "") + "')",
                                                True)
        End Try


    End Sub

    Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
        Session("ds") = ds
    End Sub

#End Region

#Region "SetForm"

    Sub CreateControlMP()
        Dim img As Image = CType(Master.FindControl("imgHead"), Image)
        img.ImageUrl = "~/img/Individual.jpg"

        Dim page As Label = CType(Master.FindControl("lblPage"), Label)
        page.Text = "ประเมินความเสี่ยง"
    End Sub

#End Region

#Region "Event Dropdrown"

    Protected Sub ddlOccupation1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlOccupation1.SelectedIndexChanged
        indexOccupationChanging1()
        'txtDes1.Text = ""
        Dim clsDropDown As New clsMasterDropDown

        If Not ddlOccupation1.SelectedIndex = 0 Then
            ddlOccupation4.Items.Clear()
            clsDropDown.setOccupation_4(ddlOccupation4, OccCode:=ddlOccupation1.SelectedValue)
        Else
            ddlOccupation4.Items.Clear()
        End If
    End Sub

    Protected Sub ddlBusiness1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlBusiness1.SelectedIndexChanged
        indexBizChanging1()
        txtDes1.Text = ""
    End Sub

    Protected Sub ddlOccupation2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlOccupation2.SelectedIndexChanged
        indexOccupationChanging2()
        txtDes2.Text = ""
    End Sub

    Protected Sub ddlBusiness2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlBusiness2.SelectedIndexChanged
        indexBizChanging2()
        txtDes2.Text = ""
    End Sub

    Protected Sub ddlOccupation3_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlOccupation3.SelectedIndexChanged
        indexOccupationChanging3()
        txtDes3.Text = ""
    End Sub

    Protected Sub ddlBusiness3_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlBusiness3.SelectedIndexChanged
        indexBizChanging3()
        txtDes3.Text = ""
    End Sub

    Protected Sub ddlPrefixTH_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlPrefixTH.SelectedIndexChanged
        ddlPrefixEN.SelectedValue = ddlPrefixTH.SelectedValue
    End Sub

    Protected Sub ddlPrefixEN_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlPrefixEN.SelectedIndexChanged
        ddlPrefixTH.SelectedValue = ddlPrefixEN.SelectedValue
    End Sub

#End Region

#Region "Event Button"

    Protected Sub btnCompile_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCompile.Click

        Try

            If Session("chkKYC") = True Then
                statusValidation()
                Image1.ImageUrl = "~/img/icon/accept.png"
                Image2.ImageUrl = "~/img/icon/accept.png"
                Image3.ImageUrl = "~/img/icon/accept.png"
                Image4.ImageUrl = "~/img/icon/accept.png"
                Image5.ImageUrl = "~/img/icon/accept.png"
                Image6.ImageUrl = "~/img/icon/accept.png"
                Image11.ImageUrl = "~/img/icon/accept.png"
                GoTo compile
            End If

      
            ''''''''''''''''''''''
            Me.FindHeighest_Score_All()
            ''''''''''''''''''''''
            If checkBeforeCompile() = True Then


compile:

                compileCDD()
                If (Panel1.Enabled = True) Then

                    Session("chkKYC") = Nothing

                    Panel1.Enabled = False
                    btnCompile.Visible = False
                    btnEditCompile.Visible = True
                    btnReport.Visible = True

                Else
                    Panel1.Enabled = True
                    btnCompile.Visible = True
                    btnEditCompile.Visible = False
                    btnReport.Visible = False

                End If

            Else

                ScriptManager.RegisterStartupScript(sender, sender.GetType(), "message", "alert('" & strMsg & "')", True)

                txtRiskLevel.Text = ""
                lblLevel.Text = 0
                txtReason.Text = ""
                txtRiskLevel.BackColor = Drawing.Color.White

            End If

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1,
                                                UpdatePanel1.GetType(),
                                                "clientScript",
                                                "alert('" + ex.Message.Replace("'", "") + "')",
                                                True)
        End Try



    End Sub

    Protected Sub btnHistory_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnHistory.Click
        Try

            ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "window.open('CDDHistory.aspx?CUSTSEQ=" & CInt(CustSeq) & "&CUSTTYPE=1" & "','_blank','scrollbars=1,Width:800px, Height:600px')", True)

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1,
                                                UpdatePanel1.GetType(),
                                                "clientScript",
                                                "alert('" + ex.Message.Replace("'", "") + "')",
                                                True)
        End Try
    End Sub


    Public Function ValidateAcc() As Boolean
        Dim result As Boolean = True
        strMsg = ""
        If rdoAcc.SelectedIndex = -1 Then
            result = False
            strMsg &= " กรุณาเลือกบัญชี " & "\n"
        End If
        If rdoAcc.SelectedIndex = 1 Then
            If ddlAcc.SelectedIndex = 0 Then
                result = False
                strMsg &= " กรุณาเลือกเลขที่บัญชี " & "\n"

            End If
        End If

        If Not IsNumeric(txtSalaryPerMonth.Text) Then

            result = False
            strMsg &= " ระบุเงินเดือนไม่ถูกต้อง " & "\n"
        End If


        Return result
    End Function

    Protected Sub btnReport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReport.Click
        Try
            Dim intANSWERTYPE As Integer = 0
            If Request.QueryString("KYC") = 1 Then
                intANSWERTYPE = 1
            ElseIf Request.QueryString("KYC") = 2 Then
                intANSWERTYPE = 3
            ElseIf Request.QueryString("KYC") = 3 Then
                intANSWERTYPE = 5
            ElseIf Request.QueryString("KYC") = 4 Then
                intANSWERTYPE = 0
            End If

            If rdoAcc.SelectedIndex = 0 Then
                clsSessionMenuRight = Session("clsMenuRight")
                If Not TypeKYC = 1 Then

                    Dim qryRKYc = From tblKYC In KYCEntity.RKYC _
                                           Where tblKYC.CUSTSEQ = CustSeq And _
                                                 tblKYC.UPDATEBY = clsSessionMenuRight.getUserName And tblKYC.ACCOUNTNO = Nothing _
                                           Select tblKYC.ANSWERTYPE, tblKYC.ACCOUNTNO

                    If Not intANSWERTYPE = 0 Then
                        qryRKYc = qryRKYc.Where(Function(fn) fn.ANSWERTYPE = intANSWERTYPE)
                    End If


                    If qryRKYc.Count = 0 Then
                        hdfChkNewAcc.Value = 0
                    Else
                        hdfChkNewAcc.Value = 1
                    End If
                Else
                    hdfChkNewAcc.Value = 0
                End If


            End If
            If hdfChkNewAcc.Value = "" Then
                hdfChkNewAcc.Value = "0"
            End If

            ''''Prachak
            'If Not hdfChkNewAcc.Value = enmStatusNewAcc.NoHaveNewAcc Then
            '    ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & "ได้มีการสร้างบัญชีไว้แล้วกรุณาไปหน้าข้อมูลKYC" & "')", True)
            '    Exit Sub
            'End If

            ''''Prachak ''''''''''''''''''''''''''''''''
            If Validate_For_All() = False Then Exit Sub
            ''''''''''''''''''''''''''''''''''''''''''''

            ''''Prachak''''''''''''
            If CInt(Me.lblLevel.Text) = 3 Then
                If checkFamily() = False Then Exit Sub
            End If

            If CInt(Me.lblLevel.Text) = 3 Then
                If checkApprove() = False Then
                    ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & strMsg & "')", True)
                    Exit Sub
                End If
            End If


            If Not ValidateAcc() Then
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & strMsg & "')", True)
                Exit Sub
            End If

            saveData()

            Session("strReason") = txtReason.Text
            ScriptManager.RegisterStartupScript(Me, Me.GetType(), "message", _
         "alert('" + Resources.resMsgKYC.msgSave + "')", True)

            ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "window.showModalDialog('../Form/KYCResult.aspx?uniqueID=" & txtUniqueID.Text.Trim & "&" _
                                             & "PrefixTH=" & ddlPrefixTH.Text & "&" _
                                             & "NameTh1=" & txtNameTh1.Text.Trim & "&" _
                                             & "NameTh2=" & txtNameTh2.Text.Trim & "&" _
                                             & "NameTh3=" & txtNameTh3.Text.Trim & "&" _
                                             & "PrefixEN=" & ddlPrefixEN.Text & "&" _
                                             & "NameEN1=" & txtNameEn1.Text.Trim & "&" _
                                             & "NameEN2=" & txtNameEn2.Text.Trim & "&" _
                                             & "NameEN3=" & txtNameEn3.Text.Trim & "&" _
                                             & "Nationality=" & ddlNationality.Text & "&" _
                                             & "Occupation1=" & ddlOccupation1.Text & "&" _
                                             & "OccOther1=" & txtOccOther1.Text.Trim & "&" _
                                             & "Business1=" & ddlBusiness1.Text & "&" _
                                             & "BizOther1=" & txtBizOther1.Text.Trim & "&" _
                                             & "Des1=" & txtDes1.Text.Trim & "&" _
                                             & "Occupation2=" & ddlOccupation2.Text & "&" _
                                             & "OccOther2=" & txtOccOther2.Text.Trim & "&" _
                                             & "Business2=" & ddlBusiness2.Text & "&" _
                                             & "BizOther2=" & txtBizOther2.Text.Trim & "&" _
                                             & "Des2=" & txtDes2.Text.Trim & "&" _
                                             & "Occupation3=" & ddlOccupation3.Text & "&" _
                                             & "OccOther3=" & txtOccOther3.Text.Trim & "&" _
                                             & "Business3=" & ddlBusiness3.Text & "&" _
                                             & "BizOther3=" & txtBizOther3.Text.Trim & "&" _
                                             & "Des3=" & txtDes3.Text.Trim & "&" _
                                             & "IncomeSource1=" & ddlIncomeSource1.Text & "&" _
                                             & "IncomeSource2=" & ddlIncomeSource2.Text & "&" _
                                             & "IncomeSource3=" & ddlIncomeSource3.Text & "&" _
                                             & "RiskLevel=" & txtRiskLevel.Text.Trim & "'" _
                                             & ", null, 'status:no; dialogWidth:1000px; dialogHeight:600px; help:no; scroll:yes; menubar:no; resizable:no')", True)




            lblLevelOld.Text = lblLevel.Text 'ระดับความเสี่ยง
            lblRiskNow.Text = "ความเสี่ยงล่าสุด : " + CStr(lblLevel.Text)
            lblRiskNow.Visible = True
            lblLevel.Text = lblLevel.Text 'ระดับความเสี่ยง

            If lblLevel.Text = 1 Then
                lblRiskNow.ForeColor = Drawing.Color.Green
            ElseIf lblLevel.Text = 2 Then
                lblRiskNow.ForeColor = Drawing.Color.Orange
            ElseIf lblLevel.Text = 3 Then
                lblRiskNow.ForeColor = Drawing.Color.Red
            End If

            Session("TypeKYC") = 2
            btnHistory.Visible = True
            SaveLog(2)
            Me.Reset_Authority()
            Me.Clear_Screen()
        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                UpdatePanel1.GetType(), _
                                                "clientScript", _
                                                "alert('" + ex.Message.Replace("'", "") + "')", _
                                                True)

        End Try
        Me.btnReport.Visible = False
    End Sub

    Sub Reset_Authority()
        Me.lblAuthor_Req_Passport.Text = "N" : Me.lblAuth_By_Passport.Text = "None"
        Me.lblAuthor_Req_Oth_Doc.Text = "N" : Me.lblAuth_By_Oth_Doc.Text = "None"
        Me.lblAuthor_Req_Nation.Text = "N" : Me.lblAuth_By_Nation.Text = "None"
        Me.lblAuthor_Req_SancList.Text = "N" : Me.lblAuth_By_SancList.Text = "None"
        Me.lblAuthor_Req_Politic.Text = "N" : Me.lblAuth_By_Politic.Text = "None"
        Me.lblAuthor_Req_Occupation.Text = "N" : Me.lblAuth_By_Occupation.Text = "None"
        Me.lblAuthor_Req_SOI.Text = "N" : Me.lblAuth_By_SOI.Text = "None"

    End Sub

    Private Function checkFamily() As Boolean
        checkFamily = False

        If Me.chkCustDeny_to_give_information.Checked = False Then
            If CInt(Me.lblCount_Family.Text) = 0 Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('กรุณาป้อนข้อมูลบุคคลในครอบครัวที่เกี่ยวข้องกับลูกค้านี้');", True)
                Exit Function
            End If
        End If

        checkFamily = True

    End Function


    Protected Sub btnKYC_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnKYC.Click
        Try
            SaveLog(1)

            If CInt(Session("KYC")) = 1 Or CInt(Session("KYC")) = 3 Then
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "window.open('../Form/KYC1T_01.aspx?CUSTSEQ=" & CInt(CustSeq) & "&Type=" & CInt(Session("KYC")) & "','_blank','scrollbars=1,Width:1000px, Height:600px')", True)
            ElseIf CInt(Session("KYC")) = 2 Then
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "window.open('../Form/KYC2T_01.aspx?CUSTSEQ=" & CInt(CustSeq) & "','_blank','scrollbars=1,Width:1000px, Height:600px')", True)

            End If

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Try

            Session("TypeKYC") = Nothing
            Session("CustSeq") = Nothing
            Response.Redirect("IndividualSearch.aspx?KYC=" & Session("KYC") & "&CustSeq=" & CustSeq & "")

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

#End Region

#Region "Function"

    Private Sub loadDataToDropDown()
        Try
            Dim clsDropDown As New clsMasterDropDown

            clsDropDown.setIDTypeToDdl(ddlUniqueType, 1) ''''Prachak
            clsDropDown.setPrefixTHToDdl(ddlPrefixTH, 1)
            clsDropDown.setPrefixENToDdl(ddlPrefixEN, 1)
            clsDropDown.setNationalityToDdl(ddlNationality)
            clsDropDown.setOccupationToDdl(ddlOccupation1, 1)
            clsDropDown.setBusinessToDdl(ddlBusiness1)
            clsDropDown.setOccupationToDdl(ddlOccupation2, 1)
            clsDropDown.setBusinessToDdl(ddlBusiness2)
            clsDropDown.setOccupationToDdl(ddlOccupation3, 1)
            clsDropDown.setBusinessToDdl(ddlBusiness3)
            clsDropDown.setCountyToDdl(ddlIncomeSource1)
            clsDropDown.setCountyToDdl(ddlIncomeSource2)
            clsDropDown.setCountyToDdl(ddlIncomeSource3)
            clsDropDown.setApproveToDdl(ddlApprove)

            ''''Prachak ''''''''''''''''
            clsDropDown.setPrefixTHToDdl(Me.ddlPrefixTH_POLITIC, 1)
            clsDropDown.setPrefixENToDdl(Me.ddlPrefixEN_POLITIC, 1)

            clsDropDown.setPrefixTHToDdl(Me.ddlPrefixTH_BO, 1)
            clsDropDown.setPrefixENToDdl(Me.ddlPrefixEN_BO, 1)

            clsDropDown.setPrefixTHToDdl(Me.ddlPrefixTH_FAM, 1)
            clsDropDown.setPrefixENToDdl(Me.ddlPrefixEN_FAM, 1)

            ''''Prachak ''''''''''''''''
            clsDropDown.setOtherDoc_To_Ddl(Me.DdOtherID)
            clsDropDown.setOtherDoc_To_Ddl(Me.ddlOTH_ID_BO)
            clsDropDown.setOtherDoc_To_Ddl(Me.ddlOTH_ID_fam)
            clsDropDown.setGenderToDdl(Me.ddlGender)
            clsDropDown.setMaritalToDdl(Me.ddlMaritalStatus)

            ''''Prachak '''''''''''''''''''''''''''''''''''
            clsDropDown.setMProductToDdl(Me.ddlPRODUCT_NAME)
            clsDropDown.setMAdditional_Service_To_Ddl(Me.ddlADDED_SERVICE)

            ddlIncomeSource1.SelectedValue = 202

            clsDropDown = Nothing
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub AutoInput()
        Try
            txtUniqueID.Text = Request.QueryString("uniqueID").Replace("*", "").Trim
            txtNameTh1.Text = Request.QueryString("FIRSTNAMETH").Replace("*", "").Trim
            txtNameTh2.Text = Request.QueryString("MIDNAMETH").Replace("*", "").Trim
            txtNameTh3.Text = Request.QueryString("LASTNAMETH").Replace("*", "").Trim
            txtNameEn1.Text = Request.QueryString("FIRSTNAMEEN").Replace("*", "").Trim
            txtNameEn2.Text = Request.QueryString("MIDNAMEEN").Replace("*", "").Trim
            txtNameEn3.Text = Request.QueryString("LASTNAMEEN").Replace("*", "").Trim
            txtPASSPORT_NO.Text = Request.QueryString("PassportNo").Replace("*", "").Trim
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub BindingData()
        Dim clsMoney As New clsMoney
        Dim clsDropDown As New clsMasterDropDown
        Try
            Dim qryKYC = (From cust In KYCEntity.MCUSTOMER
                           Where cust.CUSTSEQ = CustSeq
                          Select cust.CUSTCODE,
                                 cust.APPROVECODE,
                                 cust.TRANTYPE,
                                 cust.CUSTIDTYPE,
                                 cust.UNIQUEID,
                                 cust.THPREFIX,
                                 cust.THFIRSTNAME,
                                 cust.THMIDNAME,
                                 cust.THLASTNAME,
                                 cust.ENPREFIX,
                                 cust.ENFIRSTNAME,
                                 cust.ENMIDNAME,
                                 cust.ENLASTNAME,
                                 cust.NATIONALITY,
                                 cust.OCCUPATIONTYPE1,
                                 cust.OCCUPATIONTYPEOTHER1,
                                 cust.OCCUPATIONTYPE2,
                                 cust.OCCUPATIONTYPEOTHER2,
                                 cust.OCCUPATIONTYPE3,
                                 cust.OCCUPATIONTYPEOTHER3,
                                 cust.BIZTYPE1,
                                 cust.BIZTYPEOTHER1,
                                 cust.BIZTYPE2,
                                 cust.BIZTYPEOTHER2,
                                 cust.BIZTYPE3,
                                 cust.BIZTYPEOTHER3,
                                 cust.BIZDESC1,
                                 cust.BIZDESC2,
                                 cust.BIZDESC3,
                                 cust.INCOMESOURCE1,
                                 cust.INCOMESOURCE2,
                                 cust.INCOMESOURCE3,
                                 cust.AMLREASONSAS,
                                 cust.AMLCDDSAS,
                                 cust.AMLCDD,
                                 cust.APPROVEREASON,
                                 cust.SALARYPERMONTH,
                                 cust.ISANSWERSALARY,
                                 cust.GENDER,
                                 cust.MARITALSTATUS,
                                 cust.ID_CARD_ISSUE_DATE,
                                 cust.ID_CARD_EXP_DATE,
                                 cust.FLAG_ID_CARD_WL,
                                 cust.BIRTH_DATE_TH,
                                 cust.BIRTH_DATE_EN,
                                 cust.AVR_REVENUE,
                                 cust.AVR_EXPENSE,
                                 cust.F_POLITIC,
                                 cust.PRODUCT_NAME,
                                 cust.NEXT_REVIEW,
                                 cust.PERIOD_MONTH,
                                 cust.FILTER_RESULT,
                                 cust.RISK_LEVEL,
                                 cust.CIF_CBS_NO,
                                 cust.CIF_FDR_NO,
                                 cust.CIF_NPA_NO,
                                 cust.ADDITIONAL_SERVICE
                                 ).ToList

            If qryKYC(0).CUSTCODE = Nothing Then
                lblCIF_CBS_NO.Text = "เลขประจำตัวลูกค้า : -"
            Else
                lblCIF_CBS_NO.Text = "เลขประจำตัวลูกค้า : " + qryKYC(0).CUSTCODE.ToString
            End If


            hdfApprCode_MCus.Value = qryKYC(0).APPROVECODE.ToString
            txtReasonApp.Text = qryKYC(0).APPROVEREASON
            If Not hdfApprCode_MCus.Value = Nothing Then
                If hdfApprCode_MCus.Value = 1 Then
                    panelReasonApp.Enabled = True
                End If
            End If
            ''''Prachak '''''''''''''''''''''''''''''

            If Not qryKYC(0).PERIOD_MONTH Is Nothing Then
                Me.lblPERIOD_MONTH.Text = qryKYC(0).PERIOD_MONTH.ToString
            End If

            If Not qryKYC(0).NEXT_REVIEW Is Nothing Then
                Me.lblNEXT_REVIEW.Text = qryKYC(0).NEXT_REVIEW.ToString
            End If

            If Not qryKYC(0).FILTER_RESULT Is Nothing Then
                Me.lblFILTER_RESULT_CUST.Text = qryKYC(0).FILTER_RESULT.ToString
            End If

            If Not qryKYC(0).RISK_LEVEL Is Nothing Then
                Me.lblRISK_LEVEL_CUST.Text = qryKYC(0).RISK_LEVEL.ToString
            End If

            Me.lblCIF_CBS_NO.Text = qryKYC(0).CIF_CBS_NO
            Me.txtCIF_FDR_NO.Text = qryKYC(0).CIF_FDR_NO
            Me.txtCIF_NPA_NO.Text = qryKYC(0).CIF_NPA_NO

            Me.lblF_POLITIC.Text = qryKYC(0).F_POLITIC
            If Me.lblF_POLITIC.Text = "Y" Then
                Me.optPOL_CONNECT_Y.Checked = True
            Else
                Me.optPOL_CONNECT_N.Checked = True
            End If
            ''''''''''''''''''''''''''''''''''''
            Me.txtID_CARD_ISSUE_DATE_TH.Text = qryKYC(0).ID_CARD_ISSUE_DATE

            If Me.txtID_CARD_ISSUE_DATE_TH.Text <> "" Then
                Me.txtID_CARD_ISSUE_DD.Text = Mid(Me.txtID_CARD_ISSUE_DATE_TH.Text, 1, 2)
                Me.txtID_CARD_ISSUE_MM.Text = Mid(Me.txtID_CARD_ISSUE_DATE_TH.Text, 4, 2)
                Me.txtID_CARD_ISSUE_YYYY.Text = Mid(Me.txtID_CARD_ISSUE_DATE_TH.Text, 7, 4)
                Me.txtID_CARD_ISSUE_DATE_EN.Text = clsValid.ConcatDate(Me.txtID_CARD_ISSUE_DD.Text,
                                                   Me.txtID_CARD_ISSUE_MM.Text,
                                                   CInt(Me.txtID_CARD_ISSUE_YYYY.Text) - 543)

            End If
            ''''''''''''
            Me.txtID_CARD_EXP_DATE_TH.Text = qryKYC(0).ID_CARD_EXP_DATE

            If Me.txtID_CARD_EXP_DATE_TH.Text <> "" Then
                Me.txtID_CARD_EXP_DD.Text = Mid(Me.txtID_CARD_EXP_DATE_TH.Text, 1, 2)
                Me.txtID_CARD_EXP_MM.Text = Mid(Me.txtID_CARD_EXP_DATE_TH.Text, 4, 2)
                Me.txtID_CARD_EXP_YYYY.Text = Mid(Me.txtID_CARD_EXP_DATE_TH.Text, 7, 4)
                Me.txtID_CARD_EXP_DATE_EN.Text = clsValid.ConcatDate(Me.txtID_CARD_EXP_DD.Text,
                                                   Me.txtID_CARD_EXP_MM.Text,
                                                   CInt(Me.txtID_CARD_EXP_YYYY.Text) - 543)

            End If
            ''''''''''''
            Me.lblFLAG_ID_CARD_WL.Text = qryKYC(0).FLAG_ID_CARD_WL
            If Me.lblFLAG_ID_CARD_WL.Text = "Y" Then
                Me.chkExpire_None.Checked = True
            Else
                Me.chkExpire_None.Checked = False
            End If
            '''''''''''''''''''''''''''''''''''''''''
            Me.lbBIRTH_DATE_TH.Text = qryKYC(0).BIRTH_DATE_TH
            Me.txtBIRTH_DATE_TH_DD.Text = (Mid(Me.lbBIRTH_DATE_TH.Text, 1, 2))
            Me.txtBIRTH_DATE_TH_MM.Text = (Mid(Me.lbBIRTH_DATE_TH.Text, 4, 2))
            Me.txtBIRTH_DATE_TH_YYYY.Text = (Mid(Me.lbBIRTH_DATE_TH.Text, 7, 4))


            Me.lbBIRTH_DATE_EN.Text = qryKYC(0).BIRTH_DATE_EN
            Me.txtBIRTH_DATE_EN_DD.Text = (Mid(Me.lbBIRTH_DATE_EN.Text, 1, 2))
            Me.txtBIRTH_DATE_EN_MM.Text = (Mid(Me.lbBIRTH_DATE_EN.Text, 4, 2))
            Me.txtBIRTH_DATE_EN_YYYY.Text = (Mid(Me.lbBIRTH_DATE_EN.Text, 7, 4))


            ''''เพศ '''''''''''''''''''''''''''''''''''''''''''
            If Not qryKYC(0).GENDER Is Nothing Then
                Me.ddlGender.SelectedValue = qryKYC(0).GENDER
            End If

            ''''สถานะการสมรส '''''''''''''''''''''''''''''''''''''''''''''
            If Not qryKYC(0).MARITALSTATUS Is Nothing Then
                Me.ddlMaritalStatus.SelectedValue = qryKYC(0).MARITALSTATUS
            End If
            ''''รายได้เฉลี่ยต่อเดือน '''''''''''''''''''''''''''''''''''''''''''''
            If Not qryKYC(0).AVR_REVENUE Is Nothing Then
                Me.ddlAVR_REVENUE.SelectedValue = qryKYC(0).AVR_REVENUE
            End If
            ''''ค่าใช้จ่ายเฉลี่ยต่อเดือน''''''''''''''''''''''''''''''''''''''''''''
            If Not qryKYC(0).AVR_EXPENSE Is Nothing Then
                Me.ddlAVR_EXPENSE.SelectedValue = qryKYC(0).AVR_EXPENSE
            End If
            ''''Product''''''''''''''''''''''''''''''''''''''''''''
            If Not qryKYC(0).PRODUCT_NAME Is Nothing Then
                Me.ddlPRODUCT_NAME.SelectedValue = qryKYC(0).PRODUCT_NAME
            End If

            ''''Additional Service''''''''''''''''''''''''''''''''''''''''''''
            If Not qryKYC(0).ADDITIONAL_SERVICE Is Nothing Then
                Me.ddlADDED_SERVICE.SelectedValue = qryKYC(0).ADDITIONAL_SERVICE
            End If
            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

            If Not qryKYC(0).TRANTYPE Is Nothing Then
                ddlTranType.SelectedValue = qryKYC(0).TRANTYPE
                If qryKYC(0).TRANTYPE = 1 Then
                    ddlTranType.Enabled = False
                End If
            End If

            If Not qryKYC(0).CUSTIDTYPE Is Nothing Then
                ddlUniqueType.SelectedValue = qryKYC(0).CUSTIDTYPE
            End If

            If Not qryKYC(0).UNIQUEID Is Nothing Then
                txtUniqueID.Text = qryKYC(0).UNIQUEID
                hdfUniqueID.Value = qryKYC(0).UNIQUEID
            End If


            If Not qryKYC(0).THPREFIX Is Nothing Then
                ddlPrefixTH.SelectedValue = qryKYC(0).THPREFIX
            End If
            txtNameTh1.Text = qryKYC(0).THFIRSTNAME
            txtNameTh2.Text = qryKYC(0).THMIDNAME
            txtNameTh3.Text = qryKYC(0).THLASTNAME
            If Not qryKYC(0).ENPREFIX Is Nothing Then
                ddlPrefixEN.SelectedValue = qryKYC(0).ENPREFIX
            End If
            txtNameEn1.Text = qryKYC(0).ENFIRSTNAME
            txtNameEn2.Text = qryKYC(0).ENMIDNAME
            txtNameEn3.Text = qryKYC(0).ENLASTNAME

            'If Not qryKYC(0).NATIONALITY Is Nothing Then
            '    ddlNationality.SelectedValue = qryKYC(0).NATIONALITY
            'End If

            ''''Prachak 
            ''''grid Occuption
            'If Not qryKYC(0).OCCUPATIONTYPE1 Is Nothing Then
            '    ddlOccupation1.SelectedValue = qryKYC(0).OCCUPATIONTYPE1

            '    If Not ddlOccupation1.SelectedIndex = 0 Then
            '        clsDropDown.setOccupation_4(ddlOccupation4, OccCode:=ddlOccupation1.SelectedValue)
            '    Else
            '        ddlOccupation4.Items.Clear()
            '    End If
            'End If

            txtOccOther1.Text = qryKYC(0).OCCUPATIONTYPEOTHER1
            If Not qryKYC(0).OCCUPATIONTYPE2 Is Nothing Then
                ddlOccupation2.SelectedValue = qryKYC(0).OCCUPATIONTYPE2
            End If
            txtOccOther2.Text = qryKYC(0).OCCUPATIONTYPEOTHER2
            If Not qryKYC(0).OCCUPATIONTYPE3 Is Nothing Then
                ddlOccupation3.SelectedValue = qryKYC(0).OCCUPATIONTYPE3
            End If
            txtOccOther3.Text = qryKYC(0).OCCUPATIONTYPEOTHER3
            If Not qryKYC(0).BIZTYPE1 Is Nothing Then
                ddlBusiness1.SelectedValue = qryKYC(0).BIZTYPE1
            End If
            txtBizOther1.Text = qryKYC(0).BIZTYPEOTHER1
            If Not qryKYC(0).BIZTYPE2 Is Nothing Then
                ddlBusiness2.SelectedValue = qryKYC(0).BIZTYPE2
            End If
            txtBizOther2.Text = qryKYC(0).BIZTYPEOTHER2
            If Not qryKYC(0).BIZTYPE3 Is Nothing Then
                ddlBusiness3.SelectedValue = qryKYC(0).BIZTYPE3
            End If
            txtBizOther3.Text = qryKYC(0).BIZTYPEOTHER3
            txtDes1.Text = qryKYC(0).BIZDESC1
            txtDes2.Text = qryKYC(0).BIZDESC2
            txtDes3.Text = qryKYC(0).BIZDESC3

            'If Not qryKYC(0).INCOMESOURCE1 Is Nothing Then
            '    ddlIncomeSource1.SelectedValue = qryKYC(0).INCOMESOURCE1
            'End If

            If Not qryKYC(0).INCOMESOURCE2 Is Nothing Then
                ddlIncomeSource2.SelectedValue = qryKYC(0).INCOMESOURCE2
            End If

            If Not qryKYC(0).INCOMESOURCE3 Is Nothing Then
                ddlIncomeSource3.SelectedValue = qryKYC(0).INCOMESOURCE3
            End If

            If Not qryKYC(0).SALARYPERMONTH Is Nothing Then
                txtSalaryPerMonth.Text = clsMoney.insertComma(qryKYC(0).SALARYPERMONTH)
            Else
                txtSalaryPerMonth.Text = 0
            End If

            If Not qryKYC(0).ISANSWERSALARY Is Nothing Then
                rdoAnsSalary.SelectedValue = qryKYC(0).ISANSWERSALARY.ToString
                If rdoAnsSalary.SelectedValue = "0" Then
                    txtSalaryPerMonth.Enabled = False
                Else
                    txtSalaryPerMonth.Enabled = True
                End If
            Else
                rdoAnsSalary.SelectedValue = "0"
                txtSalaryPerMonth.Enabled = False
            End If

            txtReasonSAS.Text = qryKYC(0).AMLREASONSAS
            If Not qryKYC(0).AMLCDDSAS Is Nothing Then
                hdfAML.Value = qryKYC(0).AMLCDDSAS
            End If

            If Not qryKYC(0).AMLCDD Is Nothing Then
                If Not qryKYC(0).AMLCDD = 0 Then
                    lblLevelOld.Text = qryKYC(0).AMLCDD 'ระดับความเสี่ยง
                    'hdfLevel.Value = qryKYC(0).AMLCDD
                    lblRiskNow.Text = "ความเสี่ยงล่าสุด : " + CStr(qryKYC(0).AMLCDD)
                    lblRiskNow.Visible = True
                    lblLevel.Text = qryKYC(0).AMLCDD 'ระดับความเสี่ยง

                    If qryKYC(0).AMLCDD = 1 Then
                        lblRiskNow.ForeColor = Drawing.Color.Green
                    ElseIf qryKYC(0).AMLCDD = 2 Then
                        lblRiskNow.ForeColor = Drawing.Color.Orange
                    ElseIf qryKYC(0).AMLCDD = 3 Then
                        lblRiskNow.ForeColor = Drawing.Color.Red
                    End If
                Else
                    lblLevelOld.Text = 0
                    btnHistory.Visible = False
                End If


            Else
                lblLevelOld.Text = 0
                btnHistory.Visible = False
            End If



            qryKYC = Nothing
        Catch ex As Exception
            Throw ex
        End Try

    End Sub


    Private Sub BindingAcc(ByVal intCusSeq As Integer)
        Try
            clsDataTable = New clsLINQToDataTable

            Dim intANSWERTYPE As Integer = 0

            If Request.QueryString("KYC") = 1 Then
                intANSWERTYPE = 1
            ElseIf Request.QueryString("KYC") = 2 Then
                intANSWERTYPE = 3
            ElseIf Request.QueryString("KYC") = 3 Then
                intANSWERTYPE = 5
            ElseIf Request.QueryString("KYC") = 4 Then
                intANSWERTYPE = 0
            End If

            If ds.Tables.Contains("ShowAccAll") Then
                ds.Tables.Remove("ShowAccAll")
            End If

            Dim qryKYCAcc = From KYCAcc In KYCEntity.RKYC Where KYCAcc.CUSTSEQ = intCusSeq And Not (KYCAcc.ACCOUNTNO = Nothing)

            If Not intANSWERTYPE = 0 Then
                qryKYCAcc = qryKYCAcc.Where(Function(fn) fn.ANSWERTYPE = intANSWERTYPE)
            End If

            ds.Tables.Add(clsDataTable.LINQToDataTable(qryKYCAcc, "ShowAccAll").Copy)
            ''grdShowAccount.DataSource = ds.Tables("ShowAccAll")
            ''grdShowAccount.DataBind()
        Catch ex As Exception
            Throw ex
        End Try

    End Sub
#Region "Function Drop Drown"

    Private Sub indexOccupationChanging1()
        If Not ddlOccupation1.SelectedValue = "" Then
            ddlBusiness1.BackColor = Drawing.Color.FromArgb(255, 255, 255)

            If ddlOccupation1.SelectedValue = 98 Then 'กรณีเป็นเจ้าของกิจการ
                txtOccOther1.Visible = True

                ddlBusiness1.Enabled = True
                ddlBusiness1.BackColor = Drawing.Color.FromArgb(255, 204, 204)

            ElseIf ddlOccupation1.SelectedValue = 99 Then 'ประกอบอาชีพอื่นๆ
                txtOccOther1.Visible = True
                ddlBusiness1.Enabled = False

                ddlBusiness1.SelectedIndex = 0
                txtBizOther1.Visible = False
                txtBizOther1.Text = ""
                lblOther12.Visible = False
            Else
                txtOccOther1.Visible = True
                txtOccOther1.Text = ""
                ddlBusiness1.Enabled = False
                ddlBusiness1.SelectedIndex = 0
                txtBizOther1.Visible = False
                txtBizOther1.Text = ""
                lblOther12.Visible = False
            End If
        Else
            txtOccOther1.Visible = True
            txtOccOther1.Text = ""

            ddlBusiness1.Enabled = False

            ddlBusiness1.SelectedIndex = 0
            txtBizOther1.Visible = False
            txtBizOther1.Text = ""
            lblOther12.Visible = False
        End If
    End Sub

    Private Sub indexBizChanging1()
        If Not ddlBusiness1.SelectedValue = "" Then
            If ddlBusiness1.SelectedValue = 99 Then
                txtBizOther1.Visible = True
                lblOther12.Visible = True
            Else
                txtBizOther1.Visible = False
                txtBizOther1.Text = ""
                lblOther12.Visible = False
            End If
        Else
            txtBizOther1.Visible = False
            txtBizOther1.Text = ""
            lblOther12.Visible = False
        End If
    End Sub

    Private Sub indexOccupationChanging2()

        If Not ddlOccupation2.SelectedValue = "" Then
            ddlBusiness2.BackColor = Drawing.Color.FromArgb(255, 255, 255)

            If ddlOccupation2.SelectedValue = 98 Then 'กรณีเป็นเจ้าของกิจการ
                txtOccOther2.Visible = False
                lblOther21.Visible = False
                ddlBusiness2.Enabled = True
                ddlBusiness2.BackColor = Drawing.Color.FromArgb(255, 204, 204)

            ElseIf ddlOccupation2.SelectedValue = 99 Then 'ประกอบอาชีพอื่นๆ
                txtOccOther2.Visible = True
                lblOther21.Visible = True
                ddlBusiness2.Enabled = False

                ddlBusiness2.SelectedIndex = 0
                txtBizOther2.Visible = False
                txtBizOther2.Text = ""
                lblOther22.Visible = False
            Else
                txtOccOther2.Visible = False
                txtOccOther2.Text = ""
                lblOther21.Visible = False
                ddlBusiness2.Enabled = False

                ddlBusiness2.SelectedIndex = 0
                txtBizOther2.Visible = False
                txtBizOther2.Text = ""
                lblOther22.Visible = False
            End If
        Else
            txtOccOther2.Visible = False
            txtOccOther2.Text = ""
            lblOther21.Visible = False
            ddlBusiness2.Enabled = False

            ddlBusiness2.SelectedIndex = 0
            txtBizOther2.Visible = False
            txtBizOther2.Text = ""
            lblOther22.Visible = False
        End If

    End Sub

    Private Sub indexBizChanging2()
        If Not ddlBusiness2.SelectedValue = "" Then
            If ddlBusiness2.SelectedValue = 99 Then
                txtBizOther2.Visible = True
                lblOther22.Visible = True
            Else
                txtBizOther2.Visible = False
                txtBizOther2.Text = ""
                lblOther22.Visible = False
            End If
        Else
            txtBizOther2.Visible = False
            txtBizOther2.Text = ""
            lblOther22.Visible = False
        End If

    End Sub

    Private Sub indexOccupationChanging3()

        If Not ddlOccupation3.SelectedValue = "" Then
            ddlBusiness3.BackColor = Drawing.Color.FromArgb(255, 255, 255)

            If ddlOccupation3.SelectedValue = 98 Then 'กรณีเป็นเจ้าของกิจการ
                txtOccOther3.Visible = False
                lblOther31.Visible = False
                ddlBusiness3.Enabled = True
                ddlBusiness3.BackColor = Drawing.Color.FromArgb(255, 204, 204)

            ElseIf ddlOccupation3.SelectedValue = 99 Then 'ประกอบอาชีพอื่นๆ
                txtOccOther3.Visible = True
                lblOther31.Visible = True
                ddlBusiness3.Enabled = False

                ddlBusiness3.SelectedIndex = 0
                txtBizOther3.Visible = False
                txtBizOther3.Text = ""
                lblOther32.Visible = False
            Else
                txtOccOther3.Visible = False
                txtOccOther3.Text = ""
                lblOther31.Visible = False
                ddlBusiness3.Enabled = False

                ddlBusiness3.SelectedIndex = 0
                txtBizOther3.Visible = False
                txtBizOther3.Text = ""
                lblOther32.Visible = False
            End If
        Else
            txtOccOther3.Visible = False
            txtOccOther3.Text = ""
            lblOther31.Visible = False
            ddlBusiness3.Enabled = False

            ddlBusiness3.SelectedIndex = 0
            txtBizOther3.Visible = False
            txtBizOther3.Text = ""
            lblOther32.Visible = False
        End If


    End Sub

    Private Sub indexBizChanging3()

        If Not ddlBusiness3.SelectedValue = "" Then

            If ddlBusiness3.SelectedValue = 99 Then
                txtBizOther3.Visible = True
                lblOther32.Visible = True
            Else
                txtBizOther3.Visible = False
                txtBizOther3.Text = ""
                lblOther32.Visible = False
            End If
        Else
            txtBizOther3.Visible = False
            txtBizOther3.Text = ""
            lblOther32.Visible = False
        End If

    End Sub

#End Region

    Private Function checkApprove() As Boolean
        Try
            Dim result As Boolean = True

            ''''Prachak Oct 27, 2014
            If CInt(lblLevel.Text) = 3 Then
                PanelApprove.Enabled = True
            Else
                PanelApprove.Enabled = False
                'Exit Function
                Return False
            End If


            ' If CInt(lblLevel.Text) > 1 Then

            ''''Prachak Oct 27, 2014 Enabled
            If PanelApprove.Enabled = True Then
                If ddlApprove.SelectedIndex = 0 Then
                    result = False
                    Image7.ImageUrl = "~/img/icon/cancel.png"
                    Image7.Visible = True
                    strMsg = strMsg + Resources.resMsgAlertKYC.NotStatusApprove + "\n"
                    'ElseIf ddlApprove.SelectedIndex = 1 Then
                    '    Image7.ImageUrl = "~/img/icon/accept.png"
                ElseIf ddlApprove.SelectedValue = 2 Or ddlApprove.SelectedValue = 3 Then
                    Image7.ImageUrl = "~/img/icon/accept.png"

                    'If txtApprove.Text.Trim = "" Then
                    '    result = False
                    '    Image8.ImageUrl = "~/img/icon/cancel.png"
                    '    strMsg = strMsg + Resources.resMsgAlertKYC.NotApproveName + "\n"
                    'Else
                    '    Image8.ImageUrl = "~/img/icon/accept.png"
                    'End If


                    If txtApproveNo.Text.Trim = "" Then
                        result = False
                        Image9.ImageUrl = "~/img/icon/cancel.png"
                        strMsg = strMsg + Resources.resMsgAlertKYC.NotApproveNo + "\n"
                    Else
                        Dim clsCheckApprove As clsCheckApprove = New clsCheckApprove
                        Dim strApp As String = clsCheckApprove.checkRightApprove(txtApproveNo.Text, clsSessionMenuRight.getUserName, clsSessionMenuRight.getRoleGroup, clsSessionMenuRight.getBranchCode, clsSessionMenuRight.getZoneCode, clsSessionMenuRight.getDeptCode, txtApprovePassword.Text)

                        If strApp = "" Then
                            Image9.ImageUrl = "~/img/icon/accept.png"
                        Else
                            result = False
                            Image9.ImageUrl = "~/img/icon/cancel.png"
                            strMsg = strMsg + strApp + "\n"
                        End If
                    End If

                    If txtDApproveDate.Text = "" Then
                        result = False
                        Image10.ImageUrl = "~/img/icon/cancel.png"
                        strMsg = strMsg + Resources.resMsgAlertKYC.NotApproveDate + "\n"
                    Else
                        Image10.ImageUrl = "~/img/icon/accept.png"
                    End If

                    Image7.Visible = True
                    'Image8.Visible = True
                    Image9.Visible = True
                    Image10.Visible = True
                End If
            End If

            Return result
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    Private Function checkSalaryPerMonth() As Boolean
        Dim chk As Boolean = True

        Return chk
    End Function

    Private Function checkBeforeCompile() As Boolean
        Try
            clsCheckLanguage = New clsCheckLanguage
            clsCheckID = New clsCheckID
            Dim result As Boolean = True

            If ddlTranType.SelectedIndex = 0 Then
                result = False
                Image11.ImageUrl = "~/img/icon/cancel.png"
                strMsg = strMsg + Resources.resMsgAlertKYC.NotTranType + "\n"
            Else
                Image11.ImageUrl = "~/img/icon/accept.png"
            End If

            If ddlUniqueType.SelectedIndex = 0 Then
                result = False
                Image1.ImageUrl = "~/img/icon/cancel.png"
                strMsg = strMsg + Resources.resMsgAlertKYC.NotIDType + "\n"
            ElseIf ddlUniqueType.SelectedValue = 1 Then
                If Not txtUniqueID.Text.Trim.Length = 13 Then
                    result = False
                    Image1.ImageUrl = "~/img/icon/cancel.png"
                    strMsg = strMsg + Resources.resMsgAlertKYC.UniqueComplete + "\n"
                Else
                    If Not txtUniqueID.Text = hdfUniqueID.Value Then
                        If Not (clsCheckID.chkIDcard(txtUniqueID.Text.Trim)) Then
                            result = False
                            Image1.ImageUrl = "~/img/icon/cancel.png"
                            strMsg = strMsg + String.Format(clsCheckID.Msg) + "\n"
                        ElseIf clsCheckID.checkUniqueID1(txtUniqueID.Text, TypeKYC, CustSeq) = False Then
                            result = False
                            Image1.ImageUrl = "~/img/icon/cancel.png"
                            clsCheckID = Nothing
                            strMsg = strMsg + Resources.resMsgAlertKYC.UniqueID + "\n"

                        Else
                            Image1.ImageUrl = "~/img/icon/accept.png"
                        End If
                    Else
                        Image1.ImageUrl = "~/img/icon/accept.png"
                    End If

                End If
            Else
                If txtUniqueID.Text.Trim.Length = 0 Then
                    result = False
                    Image1.ImageUrl = "~/img/icon/cancel.png"
                    strMsg = strMsg + Resources.resMsgAlertKYC.NotID + "\n"
                Else
                    If Not txtUniqueID.Text = hdfUniqueID.Value Then
                        If clsCheckID.checkUniqueID1(txtUniqueID.Text, TypeKYC, CustSeq) = False Then
                            result = False
                            Image1.ImageUrl = "~/img/icon/cancel.png"
                            clsCheckID = Nothing
                            strMsg = strMsg + Resources.resMsgAlertKYC.UniqueID + "\n"
                        Else
                            Image1.ImageUrl = "~/img/icon/accept.png"
                        End If
                    Else
                        Image1.ImageUrl = "~/img/icon/accept.png"
                    End If
                End If
            End If


            If Not ddlNationality.SelectedIndex = 0 Then

                If CInt(ddlNationality.SelectedItem.Value) = 202 Then
                    If ddlPrefixTH.SelectedIndex = 0 And txtNameTh1.Text.Trim = "" And txtNameTh3.Text.Trim = "" Then
                        result = False
                        Image2.ImageUrl = "~/img/icon/cancel.png"
                        strMsg = strMsg + Resources.resMsgAlertKYC.NotNameTH + "\n"
                    Else

                        ''''Prachak'''''''''''''''
                        If CInt(Me.lblCount_Nation.Text) = 0 Then
                            strMsg = strMsg + "ป้อนขัอมูลในตาราง-สัญชาติ-ให้ครบถ้วน" + "\n"
                            result = False
                            Image2.ImageUrl = "~/img/icon/cancel.png"
                        Else
                            Image2.ImageUrl = "~/img/icon/accept.png"
                        End If
                        ''''''''''''''''''''''''''
                        'If CInt(Me.lblCount_OCC.Text) = 0 Then
                        '    strMsg = strMsg + "ป้อนขัอมูลในตาราง-อาชีพ-ให้ครบถ้วน" + "\n"
                        '    result = False
                        '    Image2.ImageUrl = "~/img/icon/cancel.png"
                        'Else
                        '    Image2.ImageUrl = "~/img/icon/accept.png"
                        'End If
                        ' ''''''''''''''''''''''''''
                        'If CInt(Me.lblCount_Inc_Source.Text) = 0 Then
                        '    strMsg = strMsg + "ป้อนขัอมูลในตาราง-แหล่งเงิน-ให้ครบถ้วน" + "\n"
                        '    result = False
                        '    Image2.ImageUrl = "~/img/icon/cancel.png"
                        'Else
                        '    Image2.ImageUrl = "~/img/icon/accept.png"
                        'End If
                        '' ''''''''''''''''''''''''''
                        If Me.lblFILTER_RESULT_CUST.Text = "" Then
                            strMsg = strMsg + "ต้องตรวจกรองรายชื่อก่อนทำการประเมินความเสี่ยง" + "\n"
                            result = False
                            Image2.ImageUrl = "~/img/icon/cancel.png"
                        Else
                            Image2.ImageUrl = "~/img/icon/accept.png"
                        End If


                        If ddlPrefixTH.SelectedIndex = 0 Then
                            result = False
                            Image2.ImageUrl = "~/img/icon/cancel.png"
                            strMsg = strMsg + Resources.resMsgAlertKYC.NotTHPrefix + "\n"
                            GoTo TH
                        ElseIf txtNameTh1.Text.Trim = "" Then
                            result = False
                            Image2.ImageUrl = "~/img/icon/cancel.png"
                            strMsg = strMsg + Resources.resMsgAlertKYC.NotTHFirstName + "\n"
                            GoTo TH
                        ElseIf Not (txtNameTh1.Text.Trim >= "ก" And txtNameTh1.Text.Trim <= "ฮ") Then
                            result = False
                            Image2.ImageUrl = "~/img/icon/cancel.png"
                            strMsg = strMsg + Resources.resMsgAlertKYC.NotTHFirstName + "\n"
                            GoTo TH
                        ElseIf txtNameTh3.Text.Trim = "" Then
                            result = False
                            Image2.ImageUrl = "~/img/icon/cancel.png"
                            strMsg = strMsg + Resources.resMsgAlertKYC.NotTHLastName + "\n"
                            GoTo TH
                        ElseIf clsCheckLanguage.checkLanguageTH(txtNameTh1.Text.Trim, txtNameTh2.Text.Trim, txtNameTh3.Text.Trim) = False Then
                            strMsg = strMsg + Resources.resMsgKYC.msgTH + "\n"
                            result = False
                            Image2.ImageUrl = "~/img/icon/cancel.png"
                        Else
                            Image2.ImageUrl = "~/img/icon/accept.png"
                        End If
                    End If
                End If
            End If



TH:
            If ddlPrefixEN.SelectedIndex = 0 And txtNameEn1.Text.Trim = "" And txtNameEn3.Text.Trim = "" Then
                result = False
                Image3.ImageUrl = "~/img/icon/cancel.png"
                strMsg = strMsg + Resources.resMsgAlertKYC.NotNameEN + "\n"
            Else
                If ddlPrefixEN.SelectedIndex = 0 Then
                    result = False
                    Image3.ImageUrl = "~/img/icon/cancel.png"
                    strMsg = strMsg + Resources.resMsgAlertKYC.NotENPrefix + "\n"
                    GoTo EN
                ElseIf txtNameEn1.Text.Trim = "" Then
                    result = False
                    Image3.ImageUrl = "~/img/icon/cancel.png"
                    strMsg = strMsg + Resources.resMsgAlertKYC.NotENFirstName + "\n"
                    GoTo EN
                ElseIf Not ((txtNameEn1.Text.Trim >= "A" And txtNameEn1.Text.Trim <= "Z") Or (txtNameEn1.Text.Trim >= "a" And txtNameEn1.Text.Trim <= "z")) Then
                    result = False
                    Image3.ImageUrl = "~/img/icon/cancel.png"
                    strMsg = strMsg + Resources.resMsgAlertKYC.NotENFirstName + "\n"
                    GoTo EN
                ElseIf txtNameEn3.Text.Trim = "" Then
                    result = False
                    Image3.ImageUrl = "~/img/icon/cancel.png"
                    strMsg = strMsg + Resources.resMsgAlertKYC.NotENLastName + "\n"
                    GoTo EN
                ElseIf clsCheckLanguage.checkLanguageEN(txtNameEn1.Text.Trim, txtNameEn2.Text.Trim, txtNameEn3.Text.Trim) = False Then
                    strMsg = strMsg + Resources.resMsgKYC.msgEN + "\n"
                    result = False
                    Image3.ImageUrl = "~/img/icon/cancel.png"
                Else
                    Image3.ImageUrl = "~/img/icon/accept.png"
                End If
            End If

EN:
            If ddlNationality.SelectedIndex = 0 Then
                result = False
                Image4.ImageUrl = "~/img/icon/cancel.png"
                strMsg = strMsg + Resources.resMsgAlertKYC.NotNationality + "\n"
            Else
                Image4.ImageUrl = "~/img/icon/accept.png"
            End If


            If CInt(Me.lblCount_OCC.Text) = 0 Then
                result = False
                Image5.ImageUrl = "~/img/icon/cancel.png"
                strMsg = strMsg + "ป้อนขัอมูลในตาราง-อาชีพ-ให้ครบถ้วน" + "\n"
            Else
                If Not ddlOccupation1.SelectedIndex = 0 Then

                    ''''Prachak '''''''''''''''''''''''''''''
                    If CInt(Me.lblCount_OCC.Text) = 0 Then
                        strMsg = strMsg + "ป้อนขัอมูลในตาราง-อาชีพ-ให้ครบถ้วน" + "\n"
                        result = False
                        Image2.ImageUrl = "~/img/icon/cancel.png"
                    Else
                        Image2.ImageUrl = "~/img/icon/accept.png"
                    End If
                    ''''''''''''''''''''''''''''''''''''''''''''''''

                    If ddlOccupation1.SelectedValue = 98 Then 'เจ้าของ
                        If ddlBusiness1.SelectedIndex = 0 Then
                            result = False
                            Image5.ImageUrl = "~/img/icon/cancel.png"
                            strMsg = strMsg + Resources.resMsgAlertKYC.NotBusiness + " 1" + "\n"
                        ElseIf ddlBusiness1.SelectedValue = 99 Then
                            If txtBizOther1.Text.Trim = "" Then
                                result = False
                                Image5.ImageUrl = "~/img/icon/cancel.png"
                                strMsg = strMsg + Resources.resMsgAlertKYC.NotBusinessOther + " 1" + "\n"
                            Else
                                Image5.ImageUrl = "~/img/icon/accept.png"
                            End If
                        Else
                            Image5.ImageUrl = "~/img/icon/accept.png"
                        End If
                    ElseIf ddlOccupation1.SelectedValue = 99 Then 'อื่นๆ
                        If txtOccOther1.Text.Trim = "" Then
                            result = False
                            Image5.ImageUrl = "~/img/icon/cancel.png"
                            strMsg = strMsg + Resources.resMsgAlertKYC.NotOccupationOther + " 1" + "\n"
                        Else
                            Image5.ImageUrl = "~/img/icon/accept.png"
                        End If
                    Else
                        Image5.ImageUrl = "~/img/icon/accept.png"
                    End If
                End If

                If Not ddlOccupation2.SelectedIndex = 0 Then
                    If ddlOccupation2.SelectedValue = 98 Then 'เจ้าของ
                        If ddlBusiness2.SelectedIndex = 0 Then
                            result = False
                            Image5.ImageUrl = "~/img/icon/cancel.png"
                            strMsg = strMsg + Resources.resMsgAlertKYC.NotBusiness + " 2" + "\n"
                        ElseIf ddlBusiness2.SelectedValue = 99 Then
                            If txtBizOther2.Text.Trim = "" Then
                                result = False
                                Image5.ImageUrl = "~/img/icon/cancel.png"
                                strMsg = strMsg + Resources.resMsgAlertKYC.NotBusinessOther + " 2" + "\n"
                            Else
                                Image5.ImageUrl = "~/img/icon/accept.png"
                            End If
                        Else
                            Image5.ImageUrl = "~/img/icon/accept.png"
                        End If
                    ElseIf ddlOccupation2.SelectedValue = 99 Then 'อื่นๆ
                        If txtOccOther2.Text.Trim = "" Then
                            result = False
                            Image5.ImageUrl = "~/img/icon/cancel.png"
                            strMsg = strMsg + Resources.resMsgAlertKYC.NotOccupationOther + " 2" + "\n"
                        Else
                            Image5.ImageUrl = "~/img/icon/accept.png"
                        End If
                    Else
                        Image5.ImageUrl = "~/img/icon/accept.png"
                    End If
                End If

                If Not ddlOccupation3.SelectedIndex = 0 Then
                    If ddlOccupation3.SelectedValue = 98 Then 'เจ้าของ
                        If ddlBusiness3.SelectedIndex = 0 Then
                            result = False
                            Image5.ImageUrl = "~/img/icon/cancel.png"
                            strMsg = strMsg + Resources.resMsgAlertKYC.NotBusiness + " 3" + "\n"
                        ElseIf ddlBusiness3.SelectedValue = 99 Then
                            If txtBizOther3.Text.Trim = "" Then
                                result = False
                                Image5.ImageUrl = "~/img/icon/cancel.png"
                                strMsg = strMsg + Resources.resMsgAlertKYC.NotBusinessOther + " 3" + "\n"
                            Else
                                Image5.ImageUrl = "~/img/icon/accept.png"
                            End If
                        Else
                            Image5.ImageUrl = "~/img/icon/accept.png"
                        End If
                    ElseIf ddlOccupation3.SelectedValue = 99 Then 'อื่นๆ
                        If txtOccOther3.Text.Trim = "" Then
                            result = False
                            Image5.ImageUrl = "~/img/icon/cancel.png"
                            strMsg = strMsg + Resources.resMsgAlertKYC.NotOccupationOther + " 3" + "\n"
                        Else
                            Image5.ImageUrl = "~/img/icon/accept.png"
                        End If
                    Else
                        Image5.ImageUrl = "~/img/icon/accept.png"
                    End If
                End If
            End If


            '''''''''''''''''''''''''''''''''''''''Prachak '''''''''''''''''''''''''''''''
            If CInt(Me.lblCount_Inc_Source.Text) = 0 Then
                result = False
                Image6.ImageUrl = "~/img/icon/cancel.png"
                strMsg = strMsg + Resources.resMsgAlertKYC.NotIncomeSource + " แหล่งที่ 1 ใส่ในตารางให้ครบถ้วน" + "\n"
            Else
                Image6.ImageUrl = "~/img/icon/accept.png"
            End If

            If result = False Then
                statusValidation()
            End If

            clsCheckLanguage = Nothing

            Return result
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    Private Sub statusValidation()

        Image1.Visible = True
        Image2.Visible = True
        Image3.Visible = True
        Image4.Visible = True
        Image5.Visible = True
        Image6.Visible = True
        Image11.Visible = True
    End Sub

    Private Sub compileCDD()
        Try
            'btnNext.Visible = True
            'btnSave.Visible = True
            btnReport.Visible = True

            Dim strReason = ""
            Dim risk As Integer

            'FristRowOccDetail()

            'risk = clsRiskLevel.riskLevel(txtUniqueID.Text.Trim,
            '                              txtNameTh1.Text.Trim,
            '                              txtNameTh2.Text.Trim,
            '                              txtNameTh3.Text.Trim,
            '                              txtNameEn1.Text.Trim,
            '                              txtNameEn2.Text.Trim,
            '                              txtNameEn3.Text.Trim,
            '                              ddlOccupation1.SelectedValue,
            '                              ddlOccupation1.SelectedItem.Text,
            '                              ddlOccupation2.SelectedValue,
            '                              ddlOccupation2.SelectedItem.Text,
            '                              ddlOccupation3.SelectedValue,
            '                              ddlOccupation3.SelectedItem.Text,
            '                              ddlBusiness1.SelectedValue,
            '                              ddlBusiness1.SelectedItem.Text,
            '                              ddlBusiness2.SelectedValue,
            '                              ddlBusiness2.SelectedItem.Text,
            '                              ddlBusiness3.SelectedValue,
            '                              ddlBusiness3.SelectedItem.Text,
            '                              ddlNationality.SelectedItem.Value,
            '                              ddlNationality.SelectedItem.Text,
            '                              ddlIncomeSource1.SelectedValue,
            '                              ddlIncomeSource1.SelectedItem.Text,
            '                              ddlIncomeSource2.SelectedValue,
            '                              ddlIncomeSource2.SelectedItem.Text,
            '                              ddlIncomeSource3.SelectedValue,
            '                              ddlIncomeSource3.SelectedItem.Text,
            '                              strReason)

            risk = clsRiskLevel.CalculateRisk(Convert.ToInt32(lblEVAL_Sanct_Score.Text) _
                                                        , Convert.ToInt32(lblEVAL_OCC_SCORE.Text) _
                                                        , Convert.ToInt32(lblEVAL_NATION_SCORE.Text) _
                                                        , Convert.ToInt32(lblEVAL_RESIDENT_SCORE.Text) _
                                                        , Convert.ToInt32(lblEVAL_INC_SOURCE_SCORE.Text) _
                                                        , Convert.ToInt32(lblEVAL_PRODUCT_SCORE.Text) _
                                                        , Convert.ToInt32(lblEVAL_ADD_SERV_SCORE.Text) _
                                                        , Convert.ToInt32(lblEVAL_BIZ_TRAN_SCORE.Text) _
                                                        )

            If Not Session("Sanction") = Nothing Then
                risk = 3
                strReason = clsRiskLevel.sumString(strReason, Session("Sanction"))
                Session("Sanction") = Nothing
            End If

            If Not txtReasonSAS.Text = "" Then
                If hdfAML.Value > risk Then
                    risk = hdfAML.Value
                End If
            End If

            If risk = 1 Then
                txtRiskLevel.Text = "ลูกค้ามีความเสี่ยงระดับ 1"
                lblLevel.Text = 1
                txtReason.Text = ""
                txtRiskLevel.BackColor = Drawing.Color.LawnGreen
                ''''Prachak Oct 27, 2014
                PanelApprove.Enabled = False

                '''''Prachak''''''''''''''''
                Me.Set_Family_Enable_False()
                Me.Panel_Approve_False()
            ElseIf risk = 2 Then
                txtRiskLevel.Text = "ลูกค้ามีความเสี่ยงระดับ 2"
                lblLevel.Text = 2
                txtReason.Text = strReason
                txtRiskLevel.BackColor = Drawing.Color.Orange
                ''''Prachak Oct 27, 2014 Enabled
                PanelApprove.Enabled = False
                '''''Prachak''''''''''''''''
                Me.Set_Family_Enable_False()
                Me.Panel_Approve_False()
            ElseIf risk = 3 Then
                txtRiskLevel.Text = "ลูกค้ามีความเสี่ยงระดับ 3"
                lblLevel.Text = 3
                txtReason.Text = strReason
                txtRiskLevel.BackColor = Drawing.Color.OrangeRed
                ''''Prachak ''''''''''''
                Me.Set_Family_Enable_True()
                Me.Panel_Approve_true()
                ''''Prachak ''''''''''''
                setApprove()
            End If

            If TypeKYC = 2 Then 'กรณีลูกค้าเก่าเปิดบัญชีใหม่ เช็คความเสี่ยงว่าเปลียนแปลงหรือไม่
                If Not lblLevelOld.Text = 0 Then
                    If risk = 3 Then '
                        ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & Resources.resMsgKYC.msgLevel & risk & " " & Resources.resMsgKYC.msgLevelUp & "')", True)
                        ''''Prachak Oct 27, 2014 Enabled
                        PanelApprove.Enabled = True
                        panelReasonApp.Enabled = True
                        strReason = clsRiskLevel.sumString(strReason, "- " + Resources.resMsgKYC.msgLevelUp)
                        txtReason.Text = strReason
                        setApprove()
                    ElseIf CInt(lblLevelOld.Text) = 3 Then '
                        ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & Resources.resMsgKYC.msgLevel & risk & " " & Resources.resMsgKYC.msgLevelDown & "')", True)
                        ''''Prachak Oct 27, 2014 Enabled
                        panelReasonApp.Enabled = True
                        strReason = clsRiskLevel.sumString(strReason, "- " + Resources.resMsgKYC.msgLevelDown)
                        txtReason.Text = strReason
                        '''''Prachak ทำไม่ต้องอนุมัติ ในกรณีความเสี่ยงเดิมเป็น 3
                        ''''setApprove()  



                    Else
                        ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & Resources.resMsgKYC.msgLevel & risk & "')", True)
                    End If
                Else
                    ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & Resources.resMsgKYC.msgLevel & risk & "')", True)
                End If

            Else

                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & Resources.resMsgKYC.msgLevel & risk & "')", True)
            End If

            Me.Find_next_Review()

            'If risk > 1 Then
            '    PanelApprove.Visible = True
            '    convertDate = New clsDateFormat
            '    txtDApproveDate.Text = convertDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, Now.Date)
            '    convertDate = Nothing
            'Else
            '    PanelApprove.Visible = False
            'End If

            Session("strReason") = strReason
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Sub Find_next_Review()
        Try

            Dim dtSmartCard As DataTable = New DataTable
            Dim lvsNextMonth As DataTable = New DataTable

            Me.lblPERIOD_MONTH.Text = 0

            lvsSQL = ""
            lvsSQL += "     SELECT PERIOD_MONTH                             "
            lvsSQL += "       FROM KYCADMIN.MRISK_LEVEL                     "
            lvsSQL += "      WHERE RISK_LEVEL = '" & Me.lblLevel.Text & "'  "
            dtSmartCard = clsDatabase.QueryDataTable(lvsSQL)

            If (dtSmartCard.Rows.Count <> 0) Then
                If Not IsDBNull(dtSmartCard.Rows(0)("PERIOD_MONTH")) Then Me.lblPERIOD_MONTH.Text = dtSmartCard.Rows(0)("PERIOD_MONTH")
            End If


            lvsSQL = ""
            lvsSQL += "    SELECT TO_CHAR (ADD_MONTHS(TO_DATE (SYSDATE), '" & CInt(Me.lblPERIOD_MONTH.Text) & "'), 'DD/MM/YYYY') AS NEXT_REVIEW "
            lvsSQL += "       FROM DUAL                                                                     "
            lvsNextMonth = clsDatabase.QueryDataTable(lvsSQL)

            If (lvsNextMonth.Rows.Count <> 0) Then
                If Not IsDBNull(lvsNextMonth.Rows(0)("NEXT_REVIEW")) Then Me.lblNEXT_REVIEW.Text = lvsNextMonth.Rows(0)("NEXT_REVIEW")
                If Len(Me.lblNEXT_REVIEW.Text) = 10 Then
                    Me.lblNEXT_REVIEW.Text = Mid((Me.lblNEXT_REVIEW.Text), 1, 6) & CInt(Mid((Me.lblNEXT_REVIEW.Text), 7, 4)) + 543
                End If

            End If



        Catch ex As Exception
            '  Console.WriteLine("")
            ScriptManager.RegisterStartupScript(Page, Page.GetType(),
                                    "clientScript",
                                    "alert('" + ex.Message.Replace("'", "") + "')",
                                    True)

        End Try
    End Sub

    Sub Panel_Approve_true()
        Me.PanelApprove.Enabled = True
    End Sub

    Sub Panel_Approve_False()
        Me.PanelApprove.Enabled = False
    End Sub

    Sub setApprove()
        Try
            ''''Prachak Oct 27, 2014 Enabled
            PanelApprove.Enabled = True
            panelReasonApp.Enabled = True
            ddlApprove.SelectedIndex = 0
            txtApproveNo.Text = ""
            txtReasonApp.Text = ""
            convertDate = New clsDateFormat
            txtDApproveDate.Text = convertDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, Now.Date)
            convertDate = Nothing
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub saveData()


        clsDatabase = New clsDatabase
        KYCEntity = New KYCEntities
        KYCEntity.Connection.Open()
        Using transaction As System.Data.Common.DbTransaction = KYCEntity.Connection.BeginTransaction()
            Try

                If TypeKYC = 1 Then

                    Dim sql As String = "select " &
                    System.Configuration.ConfigurationSettings.AppSettings("SequentMCUSTOMER_S") & " from dual"
                    ds.Tables.Add(clsDatabase.QueryDataSet(sql, "GENCUST").Tables("GENCUST").Copy)
                    CustSeq = ds.Tables("GENCUST").Rows(0)("NEXTVAL")
                    Session("CUSTSEQ") = ds.Tables("GENCUST").Rows(0)("NEXTVAL")

                    '''''''''''''''
                    SaveNew(CustSeq)

                    ''''Prachak'''''''''''''''''
                    Me.Save_to_Cust_Passport(CustSeq)
                    ''''Prachak'''''''''''''''''
                    Me.Save_to_Cust_OtherDoc(CustSeq)
                    ''''Prachak'''''''''''''''''
                    Me.Save_to_Cust_Name(CustSeq)
                    ''''Prachak'''''''''''''''''
                    Me.Save_to_Cust_nation(CustSeq)
                    ''''Prachak'''''''''''''''''
                    Save_to_Cust_SanctList(CustSeq)
                    ''''Prachak'''''''''''''''''
                    Me.Save_to_Cust_Politician(CustSeq)
                    ''''Prachak'''''''''''''''''
                    Me.Save_to_Cust_Occupation(CustSeq)
                    ''''Prachak'''''''''''''''''
                    Me.Save_to_Cust_Income_source(CustSeq)
                    ''''Prachak'''''''''''''''''
                    Me.Save_to_Cust_BO(CustSeq)
                    Me.Save_BO_ID_To_Mcustomer()
                    ''''Prachak'''''''''''''''''
                    Me.Save_to_Cust_Family(CustSeq)
                    ''''Prachak'''''''''''''''''
                    Me.Save_to_Cust_Reason(CustSeq)
                    ''''Prachak''''
                    Me.Save_to_Cust_Product(CustSeq)
                    Me.Save_to_Cust_AddedService(CustSeq)
                    ''''Clear Screen ''''''''''''''
                    Me.Set_PanalReason_False()
                    Me.Set_Family_Enable_False()
                    Me.Clear_tab_Approve()
                    '''''''''''''''''''''''''''''''

                    SaveLog(3)
                ElseIf TypeKYC = 2 Then
                    saveUpdate()

                    ''''Prachak'''''''''''''''''
                    Me.Save_to_Cust_Passport(CustSeq)
                    Me.Save_to_Cust_OtherDoc(CustSeq)
                    Me.Save_to_Cust_Name(CustSeq)
                    Me.Save_to_Cust_nation(CustSeq)
                    Me.Save_to_Cust_SanctList(CustSeq)
                    Me.Save_to_Cust_Politician(CustSeq)
                    Me.Save_to_Cust_Occupation(CustSeq)
                    Me.Save_to_Cust_Income_source(CustSeq)

                    Me.Save_to_Cust_BO(CustSeq)
                    Me.Save_BO_ID_To_Mcustomer()

                    Me.Save_to_Cust_Family(CustSeq)
                    Me.Save_to_Cust_Reason(CustSeq)
                    Me.Save_to_Cust_Product(CustSeq)
                    Me.Save_to_Cust_AddedService(CustSeq)
                    ''''Clear Screen ''''''''''''''
                    Me.Set_PanalReason_False()
                    Me.Set_Family_Enable_False()
                    Me.Clear_tab_Approve()
                    '''''''''''''''''''''''''''''''

                    SaveLog(4)
                End If

                If statusTran() = 0 Then 'New
                    '''''Prachak
                    ''''' Why do they save to RKYC in this Screen ?? '''''''
                    '    If Not (Session("KYC") = "2" Or Session("KYC") = "5") Then
                    '        Dim sql As String = "select " & System.Configuration.ConfigurationSettings.AppSettings("SequentRKYC_S") & " from dual"
                    '        ds.Tables.Add(clsDatabase.QueryDataSet(sql, "GENKYC").Tables("GENKYC").Copy)
                    '        Dim KYCSeq As Integer = ds.Tables("GENKYC").Rows(0)("NEXTVAL")
                    '        saveKYC(KYCSeq)
                    '    End If

                    'Else 'Edit
                    '    If rdoAcc.SelectedIndex = 1 Then
                    '        saveUpdateKYC()
                    '    Else
                    '        If ds.Tables.Contains("GENKYC") Then
                    '            Dim KYCSeq As Integer = ds.Tables("GENKYC").Rows(0)("NEXTVAL")
                    '            saveUpdateKYC(KYCSeq)
                    '        Else
                    '            Dim sql As String = "select " & System.Configuration.ConfigurationSettings.AppSettings("SequentRKYC_S") & " from dual"
                    '            ds.Tables.Add(clsDatabase.QueryDataSet(sql, "GENKYC").Tables("GENKYC").Copy)
                    '            Dim KYCSeq As Integer = ds.Tables("GENKYC").Rows(0)("NEXTVAL")
                    '            saveKYC(KYCSeq)
                    '        End If
                    '    End If
                End If

                transaction.Commit()
            Catch ex As Exception
                transaction.Rollback()
                Throw ex
            End Try
        End Using

        KYCEntity.SaveChanges()
        KYCEntity = Nothing
        clsDatabase = Nothing
    End Sub
    Sub Clear_tab_Approve()
        ''''clear tab Approve ''''''    
        Me.ddlApprove.SelectedIndex = -1
        Me.txtApproveNo.Text = ""
        Me.txtApprovePassword.Text = ""
        Me.txtDApproveDate.Text = ""
        ''''''''''''''''''''''''''''''
        Me.PanelApprove.Enabled = False
        ''''''''''''''''''''''''''''''
    End Sub
    Sub Set_PanalReason_True()
        Me.panelReasonApp.Enabled = True
    End Sub

    Sub Set_PanalReason_False()
        Me.panelReasonApp.Enabled = False
    End Sub

    Private Function statusTran() As Integer
        Dim strAccount As String = ""

        Try
            Dim KYC As Integer = CInt(Session("KYC"))
            If KYC = 1 Then
                KYC = 1
            ElseIf KYC = 2 Then
                KYC = 3
            ElseIf KYC = 3 Then
                KYC = 5
            End If

            Dim tran As Integer
            Dim qryK = From k In KYCEntity.RKYC
                         Where k.CUSTSEQ = CustSeq And k.ANSWERTYPE = KYC
                         Select k.CUSTSEQ, k.ACCOUNTNO

            If rdoAcc.SelectedIndex = 1 Then
                strAccount = ddlAcc.SelectedValue
                qryK = qryK.Where(Function(fn) fn.ACCOUNTNO = strAccount)
            End If

            Dim i As Integer = qryK.Count
            If i = 0 Then
                tran = 0 'New
            Else
                tran = 1 'Edit
            End If

            Return tran
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    Private Sub SaveNew(ByVal key As Integer)
        Dim clsMoney As New clsMoney
        Try

            Dim newCustomer As New MCUSTOMER
            newCustomer.CUSTSEQ = key
            newCustomer.CUSTTYPE = 1
            newCustomer.CUSTSUBTYPE = 1

            newCustomer.TRANTYPE = ddlTranType.SelectedValue

            newCustomer.CUSTIDTYPE = ddlUniqueType.SelectedValue
            newCustomer.UNIQUEID = txtUniqueID.Text.Trim

            ''''Prachak
            newCustomer.FILTER_RESULT = Me.lblFILTER_RESULT_CUST.Text.Trim
            newCustomer.RISK_LEVEL = Me.lblRISK_LEVEL_CUST.Text.Trim

            newCustomer.PERIOD_MONTH = CInt(Me.lblPERIOD_MONTH.Text)
            If lblNEXT_REVIEW.Text <> "" Then
                newCustomer.NEXT_REVIEW = Me.lblNEXT_REVIEW.Text
            End If

            newCustomer.AMLCDD = lblLevel.Text.Trim
            newCustomer.AMLCDDBEFORE = lblLevel.Text.Trim

            newCustomer.AMLREASON = txtReason.Text.Trim
            newCustomer.THPREFIX = ddlPrefixTH.SelectedValue
            newCustomer.THFIRSTNAME = txtNameTh1.Text.Trim
            newCustomer.THMIDNAME = txtNameTh2.Text.Trim
            newCustomer.THLASTNAME = txtNameTh3.Text.Trim
            newCustomer.ENPREFIX = ddlPrefixEN.SelectedValue
            newCustomer.ENFIRSTNAME = txtNameEn1.Text.ToUpper.Trim
            newCustomer.ENMIDNAME = txtNameEn2.Text.ToUpper.Trim
            newCustomer.ENLASTNAME = txtNameEn3.Text.ToUpper.Trim
            newCustomer.NATIONALITY = CInt(ddlNationality.SelectedItem.Value)


            If Not ddlOccupation1.SelectedIndex = 0 Then
                newCustomer.OCCUPATIONTYPE1 = ddlOccupation1.SelectedValue
                newCustomer.OCCUPATIONTYPEOTHER1 = txtOccOther1.Text.Trim
            Else
                newCustomer.OCCUPATIONTYPE1 = Nothing
                newCustomer.OCCUPATIONTYPEOTHER1 = ""
            End If
            If Not ddlOccupation2.SelectedIndex = 0 Then
                newCustomer.OCCUPATIONTYPE2 = ddlOccupation2.SelectedValue
                newCustomer.OCCUPATIONTYPEOTHER2 = txtOccOther2.Text.Trim
            Else
                newCustomer.OCCUPATIONTYPE2 = Nothing
                newCustomer.OCCUPATIONTYPEOTHER2 = ""
            End If
            If Not ddlOccupation3.SelectedIndex = 0 Then
                newCustomer.OCCUPATIONTYPE3 = ddlOccupation3.SelectedValue
                newCustomer.OCCUPATIONTYPEOTHER3 = txtOccOther3.Text.Trim
            Else
                newCustomer.OCCUPATIONTYPE3 = Nothing
                newCustomer.OCCUPATIONTYPEOTHER3 = ""
            End If

            If Not ddlBusiness1.SelectedIndex = 0 Then
                newCustomer.BIZTYPE1 = ddlBusiness1.SelectedValue
                newCustomer.BIZTYPEOTHER1 = txtBizOther1.Text.Trim
            Else
                newCustomer.BIZTYPE1 = Nothing
                newCustomer.BIZTYPEOTHER1 = ""
            End If
            If Not ddlBusiness2.SelectedIndex = 0 Then
                newCustomer.BIZTYPE2 = ddlBusiness2.SelectedValue
                newCustomer.BIZTYPEOTHER2 = txtBizOther2.Text.Trim
            Else
                newCustomer.BIZTYPE2 = Nothing
                newCustomer.BIZTYPEOTHER2 = ""
            End If
            If Not ddlBusiness3.SelectedIndex = 0 Then
                newCustomer.BIZTYPE3 = ddlBusiness3.SelectedValue
                newCustomer.BIZTYPEOTHER3 = txtBizOther3.Text.Trim
            Else
                newCustomer.BIZTYPE3 = Nothing
                newCustomer.BIZTYPEOTHER3 = ""
            End If

            newCustomer.BIZDESC1 = txtDes1.Text.Trim
            newCustomer.BIZDESC2 = txtDes2.Text.Trim
            newCustomer.BIZDESC3 = txtDes3.Text.Trim

            If Not ddlIncomeSource1.SelectedIndex = 0 Then
                newCustomer.INCOMESOURCE1 = ddlIncomeSource1.SelectedValue
            Else
                newCustomer.INCOMESOURCE1 = Nothing
            End If
            If Not ddlIncomeSource2.SelectedIndex = 0 Then
                newCustomer.INCOMESOURCE2 = ddlIncomeSource2.SelectedValue
            Else
                newCustomer.INCOMESOURCE2 = Nothing
            End If

            If Not ddlIncomeSource3.SelectedIndex = 0 Then
                newCustomer.INCOMESOURCE3 = ddlIncomeSource2.SelectedValue
            Else
                newCustomer.INCOMESOURCE3 = Nothing
            End If

            If Session("KYC") = 1 Then
                newCustomer.DEPUPDATE = "D"
                newCustomer.DEPD = "N"
                newCustomer.DEPL = "-"
                newCustomer.DEPP = "-"
                newCustomer.DEPN = "-"
            ElseIf Session("KYC") = 2 Then
                newCustomer.DEPUPDATE = "L"
                newCustomer.DEPL = "N"
                newCustomer.DEPD = "-"
                newCustomer.DEPP = "-"
                newCustomer.DEPN = "-"
            ElseIf Session("KYC") = 3 Then
                newCustomer.DEPUPDATE = "P"
                newCustomer.DEPP = "N"
                newCustomer.DEPD = "-"
                newCustomer.DEPL = "-"
                newCustomer.DEPN = "-"
            ElseIf Session("KYC") = 5 Then
                newCustomer.DEPUPDATE = "N"
                newCustomer.DEPP = "-"
                newCustomer.DEPD = "-"
                newCustomer.DEPL = "-"
                newCustomer.DEPN = "N"
            End If
            newCustomer.UPDATEBY = clsSessionMenuRight.getUserName
            ''''Prachak Oct 27, 2014 Enabled
            If PanelApprove.Enabled = True Then
                newCustomer.APPROVECODE = ddlApprove.SelectedValue
                newCustomer.APPROVEREASON = txtReasonApp.Text
                newCustomer.LASTAPPROVECODE = ddlApprove.SelectedValue
                If txtDApproveDate.Text = "" Then
                    newCustomer.LASTAPPROVEDATE = Now
                Else
                    convertDate = New clsDateFormat
                    newCustomer.LASTAPPROVEDATE = convertDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, txtDApproveDate.Text)
                End If
                newCustomer.LASTAPPROVENAME = txtApproveNo.Text
                newCustomer.LASTAPPROVENO = txtApproveNo.Text
                newCustomer.LASTAPPROVELEVEL = lblLevel.Text
                newCustomer.LASTKYCUPDATEBY = clsSessionMenuRight.getUserName
                newCustomer.LASTKYCUPDATEDATE = Now
            Else
                newCustomer.APPROVECODE = 0
                newCustomer.APPROVEREASON = ""
                newCustomer.LASTKYCUPDATEBY = clsSessionMenuRight.getUserName
                newCustomer.LASTKYCUPDATEDATE = Now
            End If

            newCustomer.BRANCHCODE = clsSessionMenuRight.getBranchCode
            newCustomer.ZONECODE = clsSessionMenuRight.getZoneCode
            newCustomer.DEPTCODE = clsSessionMenuRight.getDeptCode
            newCustomer.ALLCODERIGHT = clsSessionMenuRight.getAllCodeRight

            newCustomer.CREATEBY = clsSessionMenuRight.getUserName
            newCustomer.CREATEDATE = Now.ToShortDateString

            newCustomer.UPDATEDATE = Now.ToShortDateString
            If Not ddlTranType.SelectedValue = 2 Then
                newCustomer.ETL_STATUS = "W"
            Else
                newCustomer.ETL_STATUS = "N"
            End If


            ''''Prachak '''''''''''''''''''''''
            newCustomer.CIF_CBS_NO = Me.lblCIF_CBS_NO.Text
            newCustomer.CIF_NPA_NO = Me.txtCIF_NPA_NO.Text
            newCustomer.CIF_FDR_NO = Me.txtCIF_FDR_NO.Text


            ''''Prachak '''''''''''''''''''''''
            newCustomer.ID_CARD_ISSUE_DATE = Me.txtID_CARD_ISSUE_DATE_TH.Text
            newCustomer.ID_CARD_EXP_DATE = Me.txtID_CARD_EXP_DATE_TH.Text
            newCustomer.FLAG_ID_CARD_WL = Me.lblFLAG_ID_CARD_WL.Text
            newCustomer.BIRTH_DATE_TH = Me.lbBIRTH_DATE_TH.Text
            newCustomer.BIRTH_DATE_EN = Me.lbBIRTH_DATE_EN.Text
            newCustomer.GENDER = Me.ddlGender.SelectedValue
            newCustomer.MARITALSTATUS = Me.ddlMaritalStatus.SelectedValue
            newCustomer.AVR_REVENUE = Me.ddlAVR_REVENUE.SelectedValue
            newCustomer.AVR_EXPENSE = Me.ddlAVR_EXPENSE.SelectedValue
            newCustomer.PRODUCT_NAME = Me.ddlPRODUCT_NAME.SelectedValue
            newCustomer.ADDITIONAL_SERVICE = Me.ddlADDED_SERVICE.SelectedValue

            ''''สาขาเจ้าของบัญชี '''''''''''''''''''''''''
            newCustomer.F_POLITIC = Me.lblF_POLITIC.Text

            KYCEntity.AddToMCUSTOMER(newCustomer)
            KYCEntity.SaveChanges()
            newCustomer = Nothing
            clsMoney = Nothing
        Catch ex As Exception
            Throw ex
        End Try
    End Sub 'บันทึกข้อมูลใหม่

    Private Sub saveUpdate()
        Dim clsMoney As New clsMoney
        Try
            Dim updateCust = (From Cust In KYCEntity.MCUSTOMER
                              Where Cust.CUSTSEQ = CustSeq
                              Select Cust).First()

            updateCust.TRANTYPE = ddlTranType.SelectedValue

            updateCust.AMLCDD = lblLevel.Text.Trim

            Try
                If Not (lblLevelOld.Text.Trim = "0" Or lblLevelOld.Text.Trim = "") Then
                    updateCust.AMLCDDBEFORE = CInt(lblLevelOld.Text.Trim)
                Else
                    updateCust.AMLCDDBEFORE = lblLevel.Text.Trim
                End If
            Catch ex As Exception
                updateCust.AMLCDDBEFORE = lblLevelOld.Text.Trim
            End Try

            ''''Prachak '''''''''''''''''''''''''''''''''''''''''''''
            updateCust.FILTER_RESULT = Me.lblFILTER_RESULT_CUST.Text.Trim
            updateCust.RISK_LEVEL = Me.lblRISK_LEVEL_CUST.Text.Trim

            updateCust.PERIOD_MONTH = CInt(Me.lblPERIOD_MONTH.Text)
            If lblNEXT_REVIEW.Text <> "" Then
                updateCust.NEXT_REVIEW = Me.lblNEXT_REVIEW.Text
            End If

            updateCust.AMLREASON = txtReason.Text.Trim
            updateCust.CUSTIDTYPE = ddlUniqueType.SelectedValue
            updateCust.UNIQUEID = txtUniqueID.Text.Trim
            updateCust.THPREFIX = ddlPrefixTH.SelectedValue
            updateCust.THFIRSTNAME = txtNameTh1.Text.Trim
            updateCust.THMIDNAME = txtNameTh2.Text.Trim
            updateCust.THLASTNAME = txtNameTh3.Text.Trim
            updateCust.ENPREFIX = ddlPrefixEN.SelectedValue
            updateCust.ENFIRSTNAME = txtNameEn1.Text.ToUpper.Trim
            updateCust.ENMIDNAME = txtNameEn2.Text.ToUpper.Trim
            updateCust.ENLASTNAME = txtNameEn3.Text.ToUpper.Trim
            updateCust.NATIONALITY = CInt(ddlNationality.SelectedItem.Value)

            If Not ddlOccupation1.SelectedIndex = 0 Then
                updateCust.OCCUPATIONTYPE1 = ddlOccupation1.SelectedValue
                updateCust.OCCUPATIONTYPEOTHER1 = txtOccOther1.Text.Trim
            Else
                updateCust.OCCUPATIONTYPE1 = Nothing
                updateCust.OCCUPATIONTYPEOTHER1 = ""
            End If
            If Not ddlOccupation2.SelectedIndex = 0 Then
                updateCust.OCCUPATIONTYPE2 = ddlOccupation2.SelectedValue
                updateCust.OCCUPATIONTYPEOTHER2 = txtOccOther2.Text.Trim
            Else
                updateCust.OCCUPATIONTYPE2 = Nothing
                updateCust.OCCUPATIONTYPEOTHER2 = ""
            End If

            If Not ddlOccupation3.SelectedIndex = 0 Then
                updateCust.OCCUPATIONTYPE3 = ddlOccupation3.SelectedValue
                updateCust.OCCUPATIONTYPEOTHER3 = txtOccOther3.Text.Trim
            Else
                updateCust.OCCUPATIONTYPE3 = Nothing
                updateCust.OCCUPATIONTYPEOTHER3 = ""
            End If

            updateCust.BIZDESC1 = txtDes1.Text.Trim
            updateCust.BIZDESC2 = txtDes2.Text.Trim
            updateCust.BIZDESC3 = txtDes3.Text.Trim

            If Not ddlBusiness1.SelectedIndex = 0 Then
                updateCust.BIZTYPE1 = ddlBusiness1.SelectedValue
                updateCust.BIZTYPEOTHER1 = txtBizOther1.Text.Trim
            Else
                updateCust.BIZTYPE1 = Nothing
                updateCust.BIZTYPEOTHER1 = ""
            End If
            If Not ddlBusiness2.SelectedIndex = 0 Then
                updateCust.BIZTYPE2 = ddlBusiness2.SelectedValue
                updateCust.BIZTYPEOTHER2 = txtBizOther2.Text.Trim
            Else
                updateCust.BIZTYPE2 = Nothing
                updateCust.BIZTYPEOTHER2 = ""
            End If
            If Not ddlBusiness3.SelectedIndex = 0 Then
                updateCust.BIZTYPE3 = ddlBusiness3.SelectedValue
                updateCust.BIZTYPEOTHER3 = txtBizOther3.Text.Trim
            Else
                updateCust.BIZTYPE3 = Nothing
                updateCust.BIZTYPEOTHER3 = ""
            End If
            If Not ddlIncomeSource1.SelectedIndex = 0 Then
                updateCust.INCOMESOURCE1 = ddlIncomeSource1.SelectedValue
            Else
                updateCust.INCOMESOURCE1 = Nothing
            End If
            If Not ddlIncomeSource2.SelectedIndex = 0 Then
                updateCust.INCOMESOURCE2 = ddlIncomeSource2.SelectedValue
            Else
                updateCust.INCOMESOURCE2 = Nothing
            End If

            If Not ddlIncomeSource3.SelectedIndex = 0 Then
                updateCust.INCOMESOURCE3 = ddlIncomeSource3.SelectedValue
            Else
                updateCust.INCOMESOURCE3 = Nothing
            End If

            If Session("KYC") = 1 Then
                updateCust.DEPUPDATE = "D"
                updateCust.DEPD = "N"
            ElseIf Session("KYC") = 2 Then
                updateCust.DEPUPDATE = "L"
                updateCust.DEPL = "N"
            ElseIf Session("KYC") = 3 Then
                updateCust.DEPUPDATE = "P"
                updateCust.DEPP = "N"
            ElseIf Session("KYC") = 5 Then
                updateCust.DEPUPDATE = "N"
                updateCust.DEPN = "N"
            End If
            updateCust.UPDATEBY = clsSessionMenuRight.getUserName
            ''''Prachak Oct 27, 2014 Enabled
            If PanelApprove.Enabled = True Then
                updateCust.APPROVECODE = ddlApprove.SelectedValue
                updateCust.APPROVEREASON = txtReasonApp.Text
                updateCust.LASTAPPROVECODE = ddlApprove.SelectedValue
                If txtDApproveDate.Text = "" Then
                    updateCust.LASTAPPROVEDATE = Now
                Else
                    convertDate = New clsDateFormat
                    updateCust.LASTAPPROVEDATE = convertDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, txtDApproveDate.Text)
                End If

                updateCust.LASTAPPROVENAME = txtApproveNo.Text
                updateCust.LASTAPPROVENO = txtApproveNo.Text
                updateCust.LASTAPPROVELEVEL = lblLevel.Text
                updateCust.LASTKYCUPDATEBY = clsSessionMenuRight.getUserName
                updateCust.LASTKYCUPDATEDATE = Now
            Else

                updateCust.APPROVECODE = 0
                updateCust.APPROVEREASON = ""
            End If



            updateCust.BRANCHCODE = clsSessionMenuRight.getBranchCode
            updateCust.ZONECODE = clsSessionMenuRight.getZoneCode
            updateCust.DEPTCODE = clsSessionMenuRight.getDeptCode
            updateCust.ALLCODERIGHT = clsSessionMenuRight.getAllCodeRight



            updateCust.UPDATEDATE = Now.ToShortDateString
            If Not ddlTranType.SelectedValue = 2 Then
                updateCust.ETL_STATUS = "W"
            Else
                updateCust.ETL_STATUS = "N"
            End If

            ''''Prachak '''''''''''''''''''''''
            updateCust.CIF_CBS_NO = Me.lblCIF_CBS_NO.Text
            updateCust.CIF_NPA_NO = Me.txtCIF_NPA_NO.Text
            updateCust.CIF_FDR_NO = Me.txtCIF_FDR_NO.Text

            ''''Prachak '''''''''''''''''''''''''''''''''''''''''''''''''''''
            updateCust.ID_CARD_ISSUE_DATE = Me.txtID_CARD_ISSUE_DATE_TH.Text
            updateCust.ID_CARD_EXP_DATE = Me.txtID_CARD_EXP_DATE_TH.Text
            updateCust.FLAG_ID_CARD_WL = Me.lblFLAG_ID_CARD_WL.Text

            updateCust.BIRTH_DATE_TH = Me.lbBIRTH_DATE_TH.Text
            updateCust.BIRTH_DATE_EN = Me.lbBIRTH_DATE_EN.Text
            updateCust.GENDER = Me.ddlGender.SelectedValue
            updateCust.MARITALSTATUS = Me.ddlMaritalStatus.SelectedValue
            updateCust.AVR_REVENUE = Me.ddlAVR_REVENUE.SelectedValue
            updateCust.AVR_EXPENSE = Me.ddlAVR_EXPENSE.SelectedValue
            updateCust.PRODUCT_NAME = Me.ddlPRODUCT_NAME.SelectedValue
            updateCust.ADDITIONAL_SERVICE = Me.ddlADDED_SERVICE.SelectedValue
            updateCust.F_POLITIC = Me.lblF_POLITIC.Text

            KYCEntity.SaveChanges()

            updateCust = Nothing
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub saveKYC(ByVal key As Integer)
        Try
            Dim KYC As Integer = CInt(Session("KYC"))
            If KYC = 1 Then
                KYC = 1
            ElseIf KYC = 2 Then
                KYC = 3
            ElseIf KYC = 3 Then
                KYC = 5
            End If
            ''''Prachak Oct 27, 2014 Enabled
            If PanelApprove.Enabled = True Then
                If ddlApprove.SelectedIndex = 2 Then
                    Exit Sub
                End If
            End If

            Dim newKYC As New RKYC
            newKYC.KYCSEQ = key
            newKYC.CUSTSEQ = CustSeq
            newKYC.KYCDATE = Now
            newKYC.ANSWERTYPE = KYC
            newKYC.TRANSTYPE = 1
            newKYC.AMLCDD = lblLevel.Text.Trim
            newKYC.AMLREASON = txtReason.Text.Trim

            Dim clsFormatDate As clsDateFormat = New clsDateFormat
            'If CInt(lblLevel.Text) > 1 Then
            newKYC.UPDATEBY = clsSessionMenuRight.getUserName

            ''''Prachak Oct 27, 2014 Enabled   insert into table RKYC
            If PanelApprove.Enabled = True Then

                newKYC.APPROVECODE = ddlApprove.SelectedValue
                newKYC.APPROVENAME = txtApproveNo.Text.Trim
                newKYC.APPROVENO = txtApproveNo.Text.Trim
                newKYC.APPROVEDATE = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, txtDApproveDate.Text)

            Else
                newKYC.APPROVECODE = Nothing
                newKYC.APPROVENAME = Nothing
                newKYC.APPROVENO = Nothing
                newKYC.APPROVEDATE = Nothing
            End If
            clsFormatDate = Nothing

            If Session("KYC") = 1 Then
                newKYC.DEPUPDATE = "D"
            ElseIf Session("KYC") = 2 Then
                newKYC.DEPUPDATE = "L"
            ElseIf Session("KYC") = 3 Then
                newKYC.DEPUPDATE = "P"
            ElseIf Session("KYC") = 5 Then
                newKYC.DEPUPDATE = "N"
            End If
            newKYC.KYCCOMPLETE = "N"
            newKYC.BRANCHCODE = clsSessionMenuRight.getBranchCode
            newKYC.ZONECODE = clsSessionMenuRight.getZoneCode
            newKYC.DEPTCODE = clsSessionMenuRight.getDeptCode
            newKYC.ALLCODERIGHT = clsSessionMenuRight.getAllCodeRight

            newKYC.CREATEBY = clsSessionMenuRight.getUserName
            newKYC.CREATEDATE = Now.ToShortDateString

            newKYC.UPDATEDATE = Now.ToShortDateString
            KYCEntity.AddToRKYC(newKYC)
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub saveUpdateKYC(Optional ByVal seqKYC As Integer = 0)
        Try
            Dim strAccount As String = ""

            Dim KYC As Integer = CInt(Session("KYC"))
            If KYC = 1 Then
                KYC = 1
            ElseIf KYC = 2 Then
                KYC = 3
            ElseIf KYC = 3 Then
                KYC = 5
            End If

            ''''Prachak Oct 27, 2014 Enabled
            If PanelApprove.Enabled = True Then
                If ddlApprove.SelectedIndex = 2 Then
                    Exit Sub
                End If
            End If
            If seqKYC = 0 Then
                strAccount = ddlAcc.SelectedValue

                Dim updateKYC = (From k In KYCEntity.RKYC
                                          Where k.CUSTSEQ = CustSeq And k.ANSWERTYPE = KYC And k.ACCOUNTNO = strAccount
                                          Select k).First

                Dim clsFormatDate As clsDateFormat = New clsDateFormat
                'If CInt(lblLevel.Text) > 1 Then
                updateKYC.UPDATEBY = clsSessionMenuRight.getUserName
                ''''Prachak Oct 27, 2014 Enabled
                If PanelApprove.Enabled = True Then

                    updateKYC.APPROVECODE = ddlApprove.SelectedValue
                    updateKYC.APPROVENAME = txtApproveNo.Text.Trim
                    updateKYC.APPROVENO = txtApproveNo.Text.Trim
                    updateKYC.APPROVEDATE = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, txtDApproveDate.Text)

                Else
                    updateKYC.APPROVECODE = Nothing
                    updateKYC.APPROVENAME = Nothing
                    updateKYC.APPROVENO = Nothing
                    updateKYC.APPROVEDATE = Nothing
                End If
                clsFormatDate = Nothing

                If Session("KYC") = 1 Then
                    updateKYC.DEPUPDATE = "D"
                ElseIf Session("KYC") = 2 Then
                    updateKYC.DEPUPDATE = "L"
                ElseIf Session("KYC") = 3 Then
                    updateKYC.DEPUPDATE = "P"
                ElseIf Session("KYC") = 5 Then
                    updateKYC.DEPUPDATE = "N"
                End If
                updateKYC.KYCCOMPLETE = "N"
                updateKYC.BRANCHCODE = clsSessionMenuRight.getBranchCode
                updateKYC.ZONECODE = clsSessionMenuRight.getZoneCode
                updateKYC.DEPTCODE = clsSessionMenuRight.getDeptCode
                updateKYC.ALLCODERIGHT = clsSessionMenuRight.getAllCodeRight

                updateKYC.AMLCDD = lblLevel.Text.Trim
                updateKYC.AMLREASON = txtReason.Text.Trim

                updateKYC.UPDATEDATE = Now.ToShortDateString


            Else
                ' strAccount = ddlAcc.SelectedValue

                Dim updateKYC = (From k In KYCEntity.RKYC
                                          Where k.CUSTSEQ = CustSeq And k.ANSWERTYPE = KYC And k.KYCSEQ = seqKYC
                                          Select k).First

                Dim clsFormatDate As clsDateFormat = New clsDateFormat
                'If CInt(lblLevel.Text) > 1 Then
                updateKYC.UPDATEBY = clsSessionMenuRight.getUserName
                ''''Prachak Oct 27, 2014 Enabled
                If PanelApprove.Enabled = True Then

                    updateKYC.APPROVECODE = ddlApprove.SelectedValue
                    updateKYC.APPROVENAME = txtApproveNo.Text.Trim
                    updateKYC.APPROVENO = txtApproveNo.Text.Trim
                    updateKYC.APPROVEDATE = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, txtDApproveDate.Text)

                Else
                    updateKYC.APPROVECODE = Nothing
                    updateKYC.APPROVENAME = Nothing
                    updateKYC.APPROVENO = Nothing
                    updateKYC.APPROVEDATE = Nothing
                End If
                clsFormatDate = Nothing

                If Session("KYC") = 1 Then
                    updateKYC.DEPUPDATE = "D"
                ElseIf Session("KYC") = 2 Then
                    updateKYC.DEPUPDATE = "L"
                ElseIf Session("KYC") = 3 Then
                    updateKYC.DEPUPDATE = "P"
                ElseIf Session("KYC") = 5 Then
                    updateKYC.DEPUPDATE = "N"
                End If
                updateKYC.KYCCOMPLETE = "N"
                updateKYC.BRANCHCODE = clsSessionMenuRight.getBranchCode
                updateKYC.ZONECODE = clsSessionMenuRight.getZoneCode
                updateKYC.DEPTCODE = clsSessionMenuRight.getDeptCode
                updateKYC.ALLCODERIGHT = clsSessionMenuRight.getAllCodeRight

                updateKYC.AMLCDD = lblLevel.Text.Trim
                updateKYC.AMLREASON = txtReason.Text.Trim

                updateKYC.UPDATEDATE = Now.ToShortDateString


            End If




        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub SaveLog(ByVal index As Integer)
        Try
            Dim program As String = ""
            If CInt(Session("KYC")) = 1 Then
                program = "M11"
            ElseIf CInt(Session("KYC")) = 2 Then
                program = "M21"
            ElseIf CInt(Session("KYC")) = 3 Then
                program = "M31"
            ElseIf CInt(Session("KYC")) = 5 Then
                program = "M51"
            Else
                program = "M41"
            End If

            Dim desc As String = ""
            If index = 1 Then
                desc = "พิมพ์ฟอร์ม KYC"
            ElseIf index = 2 Then
                desc = "พิมพ์ผลประเมินความเสี่ยง"
            ElseIf index = 3 Then
                desc = "บันทึก ผลประเมินความเสี่ยง (" + ddlUniqueType.SelectedItem.Text + " " + txtUniqueID.Text + ")"
            ElseIf index = 4 Then
                desc = "บันทึก แก้ไข ผลประเมินความเสี่ยง (" + ddlUniqueType.SelectedItem.Text + " " + txtUniqueID.Text + ")"
            End If

            Dim clsLogTransaction As New clsLogTransaction
            If index < 3 Then
                clsLogTransaction.saveLogTransaction(txtUniqueID.Text.Trim, clsSessionMenuRight.getUserName, 2, desc, program)
            Else
                clsLogTransaction.saveLogTransaction(txtUniqueID.Text.Trim, clsSessionMenuRight.getUserName, index, desc, program)
            End If

            clsLogTransaction = Nothing
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

#End Region


    Protected Sub ddlApprove_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlApprove.SelectedIndexChanged

        If ddlApprove.SelectedIndex = 0 Then
            txtApproveNo.Enabled = False
            txtApprovePassword.Enabled = False
            txtApproveNo.Text = ""
            txtApprovePassword.Text = ""
        Else
            If ddlApprove.SelectedValue = 1 Then
                txtApproveNo.Enabled = False
                txtApprovePassword.Enabled = False
                txtApproveNo.Text = ""
                txtApprovePassword.Text = ""
            Else
                txtApproveNo.Enabled = True
                txtApprovePassword.Enabled = True
            End If
        End If

    End Sub

    Protected Sub btnKYCNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnKYCNext.Click

        Try
            If ds.Tables.Contains("GENKYC") Then
                ds.Tables.Remove("GENKYC")
            End If
            If CustSeq = 0 Then
                Response.Redirect("IndividualKYC.aspx?KYC=" & Session("KYC") & "&CUSTSEQ=0&CDD=0&TypeKYC=" & TypeKYC & "")
            Else
                If TypeKYC = 1 Then
                    If rdoAcc.SelectedIndex = 1 And ddlAcc.SelectedIndex > 0 Then
                        Response.Redirect("IndividualKYC.aspx?KYC=" & Session("KYC") & "&CUSTSEQ=" & Session("CUSTSEQ") & "&CDD=" & lblLevel.Text & "&TypeKYC=" & TypeKYC & "&acc=" & ddlAcc.SelectedItem.Text & "")
                    Else
                        Response.Redirect("IndividualKYC.aspx?KYC=" & Session("KYC") & "&CUSTSEQ=" & Session("CUSTSEQ") & "&CDD=" & lblLevel.Text & "&TypeKYC=" & TypeKYC & "")
                    End If

                Else
                    If rdoAcc.SelectedIndex = 1 And ddlAcc.SelectedIndex > 0 Then
                        Response.Redirect("IndividualKYC.aspx?KYC=" & Session("KYC") & "&CUSTSEQ=" & CustSeq & "&CDD=" & lblLevel.Text & "&TypeKYC=" & TypeKYC & "&acc=" & ddlAcc.SelectedItem.Text & "")

                    Else
                        Response.Redirect("IndividualKYC.aspx?KYC=" & Session("KYC") & "&CUSTSEQ=" & CustSeq & "&CDD=" & lblLevel.Text & "&TypeKYC=" & TypeKYC & "")

                    End If
                End If
            End If

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub btnEditCompile_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnEditCompile.Click
        If (Panel1.Enabled = False) Then
            Panel1.Enabled = True
            btnCompile.Visible = True
            btnEditCompile.Visible = False
            btnReport.Visible = False
            ''''Prachak''''
            Me.Set_PanalReason_True()
            '''''''''''''''
        Else
            Panel1.Enabled = False
            btnCompile.Visible = False
            btnEditCompile.Visible = True
            btnReport.Visible = True
        End If


    End Sub

    Protected Sub rdoAcc_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rdoAcc.SelectedIndexChanged
        Dim intANSWERTYPE As Integer = 0
        If Request.QueryString("KYC") = 1 Then
            intANSWERTYPE = 1
        ElseIf Request.QueryString("KYC") = 2 Then
            intANSWERTYPE = 3
        ElseIf Request.QueryString("KYC") = 3 Then
            intANSWERTYPE = 5
        ElseIf Request.QueryString("KYC") = 4 Then
            intANSWERTYPE = 0
        End If

        If Not rdoAcc.SelectedIndex = 0 Then

            Dim AddItem As ListItem = Nothing
            AddItem = New ListItem(" กรุณาเลือกเลขที่บัญชี ", 0)
            Try
                hdfChkNewAcc.Value = 0
                If ds.Tables.Contains("ShowAccAll") Then
                    ddlAcc.DataSource = ds.Tables("ShowAccAll")
                    ddlAcc.DataValueField = "ACCOUNTNO"
                    ddlAcc.DataTextField = "ACCOUNTNO"
                    ddlAcc.DataBind()
                    If Not (AddItem Is Nothing) Then
                        ddlAcc.Items.Insert(0, AddItem)

                    End If
                    ddlAcc.SelectedIndex = 0

                Else
                    Dim clsDataTable As New clsLINQToDataTable
                    Dim qryRKYc = From tblKYC In KYCEntity.RKYC _
                                                       Where tblKYC.CUSTSEQ = CustSeq And Not (tblKYC.ACCOUNTNO = Nothing)
                                                       Select tblKYC.ANSWERTYPE, tblKYC.ACCOUNTNO


                    If Not intANSWERTYPE = 0 Then
                        qryRKYc = qryRKYc.Where(Function(fn) fn.ANSWERTYPE = intANSWERTYPE)
                    End If
                    If qryRKYc.Count > 0 Then
                        hdfChkNewAcc.Value = 1
                    End If

                    ds.Tables.Add(clsDataTable.LINQToDataTable(qryRKYc, "ShowAccAll").Copy)
                    ddlAcc.DataSource = ds.Tables("ShowAccAll")
                    ddlAcc.DataValueField = "ACCOUNTNO"
                    ddlAcc.DataTextField = "ACCOUNTNO"
                    ddlAcc.DataBind()

                    If Not (AddItem Is Nothing) Then
                        ddlAcc.Items.Insert(0, AddItem)

                    End If
                    ddlAcc.SelectedIndex = 0

                End If


            Catch ex As Exception

            End Try
            ddlAcc.Visible = True
        Else
            clsSessionMenuRight = Session("clsMenuRight")
            If Not TypeKYC = 1 Then

                Dim qryRKYc = From tblKYC In KYCEntity.RKYC _
                                       Where tblKYC.CUSTSEQ = CustSeq And _
                                             tblKYC.UPDATEBY = clsSessionMenuRight.getUserName And tblKYC.ACCOUNTNO = Nothing _
                                       Select tblKYC.ANSWERTYPE, tblKYC.ACCOUNTNO

                If Not intANSWERTYPE = 0 Then
                    qryRKYc = qryRKYc.Where(Function(fn) fn.ANSWERTYPE = intANSWERTYPE)
                End If



                If qryRKYc.Count = 0 Then
                    hdfChkNewAcc.Value = 0
                Else
                    hdfChkNewAcc.Value = 1
                End If
            Else
                hdfChkNewAcc.Value = 0
            End If



            ddlAcc.Visible = False
        End If
    End Sub

    Protected Sub rdoAnsSalary_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rdoAnsSalary.SelectedIndexChanged

        If rdoAnsSalary.SelectedIndex = 0 Then

            txtSalaryPerMonth.Text = "0"
            txtSalaryPerMonth.Enabled = False
        Else
            txtSalaryPerMonth.Enabled = True

        End If
    End Sub

    Protected Sub txtSalaryPerMonth_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtSalaryPerMonth.TextChanged
        Dim clsMoney As New clsMoney
        Dim condition As Boolean = True
        Try
            If Not txtSalaryPerMonth.Text = "" Then
                clsMoney = New clsMoney
                If clsMoney.insertComma(txtSalaryPerMonth.Text.Trim) = True Then
                    txtSalaryPerMonth.Text = clsMoney.insertComma(txtSalaryPerMonth.Text.Trim)

                End If
                clsMoney = Nothing
            End If
        Catch ex As Exception
            condition = False

            ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & clsMoney.getStrMsg & "')", True)

        End Try
        clsMoney = Nothing
    End Sub

    Protected Sub btnSAVE_NATION_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSAVE_NATION.Click
        Save_to_Cust_nation_Transaction(502)
    End Sub

    Protected Sub Save_to_Cust_Passport(ByVal key As Integer)

        Dim mPassport_No As String = ""
        Dim mIssue_Date As String = ""
        Dim mExpire_Date As String = ""
        Dim mFilter_Result As String = ""
        Dim mRisk_Level As String = ""
        Dim chActive As String = ""
        Dim lvsCustType As Integer = Session("KYC")
        '''''''''''''''''''''''

        Try

            Dim DeletedQuery = (From m In KYCEntity.MCUST_PASSPORT
                               Where m.CUSTSEQ = key _
                              Select m).ToList

            If DeletedQuery.Count > 0 Then
                For i As Integer = 0 To DeletedQuery.Count - 1
                    KYCEntity.MCUST_PASSPORT.DeleteObject(DeletedQuery(i))
                Next i
            End If
            ''''''''''''''''''''''
            For Each lvsRow_No As GridViewRow In Me.grdPassport.Rows
                Dim newCust_Passport As New MCUST_PASSPORT

                ''''get values from Gridview '''''''
                mPassport_No = lvsRow_No.Cells(1).Text : If mPassport_No = "&nbsp;" Then mPassport_No = ""
                mIssue_Date = lvsRow_No.Cells(2).Text : If mIssue_Date = "&nbsp;" Then mIssue_Date = ""
                mExpire_Date = lvsRow_No.Cells(3).Text : If mExpire_Date = "&nbsp;" Then mExpire_Date = ""
                mFilter_Result = lvsRow_No.Cells(4).Text : If mFilter_Result = "&nbsp;" Then mFilter_Result = ""
                mRisk_Level = lvsRow_No.Cells(5).Text : If mRisk_Level = "&nbsp;" Then mRisk_Level = "0"

                If (CType(lvsRow_No.Cells(6).FindControl("chActivePassport"), CheckBox).Checked = True) Then
                    chActive = "Y"
                Else
                    chActive = "N"
                End If

                ''''''''''''''''''''''''''''''''''''

                '''''''LINQ Start here ''''''''''''''
                newCust_Passport.CUSTSEQ = key
                newCust_Passport.CUSTTYPE = Session("KYC")
                newCust_Passport.SEQ = lvsRow_No.RowIndex + 1
                newCust_Passport.PASSPORT_NO = mPassport_No.Trim
                newCust_Passport.ISSUE_DATE = mIssue_Date.Trim
                newCust_Passport.EXPIRE_DATE = mExpire_Date.Trim
                newCust_Passport.FILTER_RESULT = mFilter_Result
                newCust_Passport.RISK_LEVEL = mRisk_Level
                newCust_Passport.ACTIVE = chActive
                newCust_Passport.CREATED_DATE = Now
                newCust_Passport.CREATED_BY = clsSessionMenuRight.getUserName
                KYCEntity.AddToMCUST_PASSPORT(newCust_Passport)
            Next
            KYCEntity.SaveChanges()

        Catch ex As Exception
            Throw ex

            'Catch ex As System.Data.SqlClient.SqlException
            '    Dim lvsERROR As String = ex.Message.ToString
            '    ScriptManager.RegisterStartupScript(Me, Me.GetType(), "clientScript", "alert('" & lvsERROR & "')", True)
        End Try




    End Sub

    Protected Sub Save_to_Cust_OtherDoc(ByVal key As Integer)

        Dim mDocument_Name As String = ""
        Dim mOth_Doc_ID As String = ""
        Dim mOth_Doc_NO As String = ""
        Dim chActive As String = ""
        Dim lvsCustType As Integer = Session("KYC")
        '''''''''''''''''''''''

        Try

            Dim DeletedQuery = (From m In KYCEntity.MCUST_OTH_DOC
                               Where m.CUSTSEQ = key _
                              Select m).ToList

            If DeletedQuery.Count > 0 Then
                For i As Integer = 0 To DeletedQuery.Count - 1
                    KYCEntity.MCUST_OTH_DOC.DeleteObject(DeletedQuery(i))
                Next i
            End If
            ''''''''''''''''''''''
            For Each lvsRow_No As GridViewRow In Me.grdOtherID.Rows
                Dim newCust_Oth_Doc As New MCUST_OTH_DOC


                ''''get values from Gridview '''''''
                mDocument_Name = lvsRow_No.Cells(1).Text : If mDocument_Name = "&nbsp;" Then mDocument_Name = ""
                mOth_Doc_ID = lvsRow_No.Cells(2).Text : If mOth_Doc_ID = "&nbsp;" Then mOth_Doc_ID = ""
                mOth_Doc_NO = lvsRow_No.Cells(3).Text : If mOth_Doc_NO = "&nbsp;" Then mOth_Doc_NO = ""


                If (CType(lvsRow_No.Cells(4).FindControl("chACT_OTH_DOC"), CheckBox).Checked = True) Then
                    chActive = "Y"
                Else
                    chActive = "N"
                End If

                ''''''''''''''''''''''''''''''''''''

                '''''''LINQ Start here ''''''''''''''
                newCust_Oth_Doc.CUSTSEQ = key
                newCust_Oth_Doc.CUSTTYPE = Session("KYC")
                newCust_Oth_Doc.SEQ = lvsRow_No.RowIndex + 1
                newCust_Oth_Doc.OTH_DOC_NAME = mDocument_Name.Trim
                newCust_Oth_Doc.OTH_DOC_ID = mOth_Doc_ID.Trim
                newCust_Oth_Doc.OTH_DOC_CARDID = mOth_Doc_NO.Trim
                newCust_Oth_Doc.ACTIVE = chActive
                newCust_Oth_Doc.CREATED_DATE = Now
                newCust_Oth_Doc.CREATED_BY = clsSessionMenuRight.getUserName
                KYCEntity.AddToMCUST_OTH_DOC(newCust_Oth_Doc)
            Next
            KYCEntity.SaveChanges()

        Catch ex As Exception
            Throw ex

        End Try



    End Sub

    Protected Sub Save_to_Cust_Politician(ByVal key As Integer)

        Dim mPolician_Prefix_TH As String = ""
        Dim mPolician_Prefix_Desc_TH As String = ""
        Dim mPolician_Name_TH As String = ""
        Dim mPolician_MidName_TH As String = ""
        Dim mPolician_Surname_TH As String = ""

        Dim mPolician_Prefix_EN As String = ""
        Dim mPolician_Prefix_Desc_EN As String = ""
        Dim mPolician_Name_EN As String = ""
        Dim mPolician_MidName_EN As String = ""
        Dim mPolician_Surname_EN As String = ""

        Dim mPolician_Position As String = ""
        Dim mPolician_Relation As String = ""
        Dim chActive As String = ""

        Dim lvsCustType As Integer = Session("KYC")
        '''''''''''''''''''''''

        Try

            Dim DeletedQuery = (From m In KYCEntity.MCUST_POLITICIAN_CONCERN
                               Where m.CUSTSEQ = key _
                              Select m).ToList

            If DeletedQuery.Count > 0 Then
                For i As Integer = 0 To DeletedQuery.Count - 1
                    KYCEntity.MCUST_POLITICIAN_CONCERN.DeleteObject(DeletedQuery(i))
                Next i
            End If
            ''''''''''''''''''''''
            For Each lvsRow_No As GridViewRow In Me.grdPolitical.Rows
                Dim newCust_Politician As New MCUST_POLITICIAN_CONCERN

                ''''get values from Gridview '''''''
                mPolician_Prefix_TH = lvsRow_No.Cells(1).Text : If mPolician_Prefix_TH = "&nbsp;" Then mPolician_Prefix_TH = ""
                mPolician_Prefix_Desc_TH = lvsRow_No.Cells(2).Text : If mPolician_Prefix_Desc_TH = "&nbsp;" Then mPolician_Prefix_Desc_TH = ""
                mPolician_Name_TH = lvsRow_No.Cells(3).Text : If mPolician_Name_TH = "&nbsp;" Then mPolician_Name_TH = ""
                mPolician_MidName_TH = lvsRow_No.Cells(4).Text : If mPolician_MidName_TH = "&nbsp;" Then mPolician_MidName_TH = ""
                mPolician_Surname_TH = lvsRow_No.Cells(5).Text : If mPolician_Surname_TH = "&nbsp;" Then mPolician_Surname_TH = ""

                mPolician_Prefix_EN = lvsRow_No.Cells(6).Text : If mPolician_Prefix_EN = "&nbsp;" Then mPolician_Prefix_EN = ""
                mPolician_Prefix_Desc_EN = lvsRow_No.Cells(7).Text : If mPolician_Prefix_Desc_EN = "&nbsp;" Then mPolician_Prefix_Desc_EN = ""
                mPolician_Name_EN = lvsRow_No.Cells(8).Text : If mPolician_Name_EN = "&nbsp;" Then mPolician_Name_EN = ""
                mPolician_MidName_EN = lvsRow_No.Cells(9).Text : If mPolician_MidName_EN = "&nbsp;" Then mPolician_MidName_EN = ""
                mPolician_Surname_EN = lvsRow_No.Cells(10).Text : If mPolician_Surname_EN = "&nbsp;" Then mPolician_Surname_EN = ""

                mPolician_Position = lvsRow_No.Cells(11).Text : If mPolician_Position = "&nbsp;" Then mPolician_Position = ""
                mPolician_Relation = lvsRow_No.Cells(12).Text : If mPolician_Relation = "&nbsp;" Then mPolician_Relation = ""


                If (CType(lvsRow_No.Cells(13).FindControl("chk_ACT_POLTIC"), CheckBox).Checked = True) Then
                    chActive = "Y"
                Else
                    chActive = "N"
                End If

                ''''''''''''''''''''''''''''''''''''


                '''''''LINQ Start here '''''''''''''
                newCust_Politician.CUSTSEQ = key
                newCust_Politician.CUSTTYPE = Session("KYC")
                newCust_Politician.SEQ = lvsRow_No.RowIndex + 1

                newCust_Politician.THPREFIX = CInt(mPolician_Prefix_TH.Trim)
                newCust_Politician.THPREFIX_DESC = mPolician_Prefix_Desc_TH.Trim
                newCust_Politician.THFIRSTNAME = mPolician_Name_TH.Trim
                newCust_Politician.THMIDNAME = mPolician_MidName_TH.Trim
                newCust_Politician.THLASTNAME = mPolician_Surname_TH.Trim

                newCust_Politician.ENPREFIX = CInt(mPolician_Prefix_EN.Trim)
                newCust_Politician.ENPREFIX_DESC = mPolician_Prefix_Desc_EN.Trim
                newCust_Politician.ENFIRSTNAME = mPolician_Name_EN.Trim
                newCust_Politician.ENMIDNAME = mPolician_MidName_EN.Trim
                newCust_Politician.ENLASTNAME = mPolician_Surname_EN.Trim

                newCust_Politician.POLITIC_RELATION = mPolician_Relation.Trim
                newCust_Politician.POLITIC_POST_CONC = mPolician_Position.Trim
                newCust_Politician.ACTIVE = chActive
                newCust_Politician.CREATED_DATE = Now
                newCust_Politician.CREATED_BY = clsSessionMenuRight.getUserName
                KYCEntity.AddToMCUST_POLITICIAN_CONCERN(newCust_Politician)
            Next
            KYCEntity.SaveChanges()

        Catch ex As Exception
            Throw ex

        End Try


    End Sub

    Protected Sub Save_to_Cust_BO(ByVal key As Integer)


        Dim mBO_Cif_No As String = ""
        Dim mBO_UniqueID As String = ""
        Dim mBO_PassportNo As String = ""

        Dim mBO_OTH_ID_TYPE As String = ""
        Dim mBO_OTH_ID_DESC As String = ""
        Dim mBO_OTH_ID_NO As String = ""

        Dim mBO_THPREFIX As String = ""
        Dim mBO_THPREFIX_Desc As String = ""
        Dim mBO_THFIRSTNAME As String = ""
        Dim mBO_THMIDNAME As String = ""
        Dim mBO_THLASTNAME As String = ""

        Dim mBO_ENPREFIX As String = ""
        Dim mBO_ENPREFIX_Desc As String = ""
        Dim mBO_ENFIRSTNAME As String = ""
        Dim mBO_ENMIDNAME As String = ""
        Dim mBO_ENLASTNAME As String = ""

        Dim mBO_Relation As String = ""

        Dim mBO_Filter_Result As String = ""
        Dim mBO_Risk_level As String = ""
        Dim chActive As String = ""

        Dim lvsCustType As Integer = Session("KYC")
        '''''''''''''''''''''''

        Try

            Dim DeletedQuery = (From m In KYCEntity.MCUST_BO
                               Where m.CUSTSEQ = key _
                              Select m).ToList

            If DeletedQuery.Count > 0 Then
                For i As Integer = 0 To DeletedQuery.Count - 1
                    KYCEntity.MCUST_BO.DeleteObject(DeletedQuery(i))
                Next i
            End If
            ''''''''''''''''''''''
            For Each lvsRow_No As GridViewRow In Me.grdBo.Rows
                Dim newCust_BO As New MCUST_BO

                ''''get values from Gridview '''''''

                mBO_Cif_No = lvsRow_No.Cells(1).Text : If mBO_Cif_No = "&nbsp;" Then mBO_Cif_No = ""
                mBO_UniqueID = lvsRow_No.Cells(2).Text : If mBO_UniqueID = "&nbsp;" Then mBO_UniqueID = ""
                mBO_PassportNo = lvsRow_No.Cells(3).Text : If mBO_PassportNo = "&nbsp;" Then mBO_PassportNo = ""

                mBO_OTH_ID_TYPE = lvsRow_No.Cells(4).Text : If mBO_OTH_ID_TYPE = "&nbsp;" Then mBO_OTH_ID_TYPE = ""
                mBO_OTH_ID_DESC = lvsRow_No.Cells(5).Text : If mBO_OTH_ID_DESC = "&nbsp;" Then mBO_OTH_ID_DESC = ""
                mBO_OTH_ID_NO = lvsRow_No.Cells(6).Text : If mBO_OTH_ID_NO = "&nbsp;" Then mBO_OTH_ID_NO = ""

                mBO_THPREFIX = lvsRow_No.Cells(7).Text : If mBO_THPREFIX = "&nbsp;" Then mBO_THPREFIX = ""
                mBO_THPREFIX_Desc = lvsRow_No.Cells(8).Text : If mBO_THPREFIX_Desc = "&nbsp;" Then mBO_THPREFIX_Desc = ""
                mBO_THFIRSTNAME = lvsRow_No.Cells(9).Text : If mBO_THFIRSTNAME = "&nbsp;" Then mBO_THFIRSTNAME = ""
                mBO_THMIDNAME = lvsRow_No.Cells(10).Text : If mBO_THMIDNAME = "&nbsp;" Then mBO_THMIDNAME = ""
                mBO_THLASTNAME = lvsRow_No.Cells(11).Text : If mBO_THLASTNAME = "&nbsp;" Then mBO_THLASTNAME = ""

                mBO_ENPREFIX = lvsRow_No.Cells(12).Text : If mBO_ENPREFIX = "&nbsp;" Then mBO_ENPREFIX = ""
                mBO_ENPREFIX_Desc = lvsRow_No.Cells(13).Text : If mBO_ENPREFIX_Desc = "&nbsp;" Then mBO_ENPREFIX_Desc = ""
                mBO_ENFIRSTNAME = lvsRow_No.Cells(14).Text : If mBO_ENFIRSTNAME = "&nbsp;" Then mBO_ENFIRSTNAME = ""
                mBO_ENMIDNAME = lvsRow_No.Cells(15).Text : If mBO_ENMIDNAME = "&nbsp;" Then mBO_ENMIDNAME = ""
                mBO_ENLASTNAME = lvsRow_No.Cells(16).Text : If mBO_ENLASTNAME = "&nbsp;" Then mBO_ENLASTNAME = ""

                mBO_Relation = lvsRow_No.Cells(17).Text : If mBO_Relation = "&nbsp;" Then mBO_Relation = ""

                mBO_Filter_Result = lvsRow_No.Cells(18).Text : If mBO_Filter_Result = "&nbsp;" Then mBO_Filter_Result = ""
                mBO_Risk_level = lvsRow_No.Cells(19).Text : If mBO_Risk_level = "&nbsp;" Then mBO_Risk_level = "1"

                If (CType(lvsRow_No.Cells(20).FindControl("chk_ACT_CUST_BO"), CheckBox).Checked = True) Then
                    chActive = "Y"
                Else
                    chActive = "N"
                End If

                ''''''''''''''''''''''''''''''''''''

                '''''''LINQ Start here '''''''''''''
                newCust_BO.CUSTSEQ = key
                newCust_BO.CUSTTYPE = Session("KYC")
                newCust_BO.SEQ = lvsRow_No.RowIndex + 1
                newCust_BO.CIF_NO = mBO_Cif_No.Trim
                newCust_BO.UNIQUEID = mBO_UniqueID.Trim
                newCust_BO.PASSPORT_NO = mBO_PassportNo.Trim

                newCust_BO.OTH_ID_TYPE = mBO_OTH_ID_TYPE.Trim
                newCust_BO.OTH_ID_DESC = mBO_OTH_ID_DESC.Trim
                newCust_BO.OTH_ID_NO = mBO_OTH_ID_NO.Trim

                newCust_BO.THPREFIX = mBO_THPREFIX.Trim
                newCust_BO.THPREFIX_DESC = mBO_THPREFIX_Desc.Trim
                newCust_BO.THFIRSTNAME = mBO_THFIRSTNAME.Trim
                newCust_BO.THMIDNAME = mBO_THMIDNAME.Trim
                newCust_BO.THLASTNAME = mBO_THLASTNAME.Trim

                newCust_BO.ENPREFIX = mBO_ENPREFIX.Trim
                newCust_BO.ENPREFIX_DESC = mBO_ENPREFIX_Desc.Trim
                newCust_BO.ENFIRSTNAME = mBO_ENFIRSTNAME.Trim
                newCust_BO.ENMIDNAME = mBO_ENMIDNAME.Trim
                newCust_BO.ENLASTNAME = mBO_ENLASTNAME.Trim

                newCust_BO.ACC_OWN_RELATION = mBO_Relation.Trim

                newCust_BO.FILTER_RESULT = mBO_Filter_Result.Trim
                newCust_BO.RISK_LEVEL = mBO_Risk_level

                newCust_BO.ACTIVE = chActive
                newCust_BO.CREATED_DATE = Now
                newCust_BO.CREATED_BY = clsSessionMenuRight.getUserName
                KYCEntity.AddToMCUST_BO(newCust_BO)

            Next
            KYCEntity.SaveChanges()

        Catch ex As Exception
            Throw ex

        End Try


    End Sub

    Protected Sub Save_BO_ID_To_Mcustomer()

        Dim dtSmartCard As DataTable = New DataTable
        Dim CustSeq_BO As Integer = 0
        Dim mBO_Cif_No As String = ""
        Dim mBO_UniqueID As String = ""

        Dim mBO_THPREFIX As String = ""
        Dim mBO_THFIRSTNAME As String = ""
        Dim mBO_THMIDNAME As String = ""
        Dim mBO_THLASTNAME As String = ""

        Dim mBO_ENPREFIX As String = ""
        Dim mBO_ENFIRSTNAME As String = ""
        Dim mBO_ENMIDNAME As String = ""
        Dim mBO_ENLASTNAME As String = ""

        Dim mBO_Filter_Result As String = ""
        Dim mBO_Risk_Level As String = ""
        Dim mBO_Relation As String = ""
        Dim chActive As String = ""
        Dim lvsCustType As Integer = Session("KYC")
        '''''''''''''''''''''''
        Try

            ''''''''''''''''''''''
            For Each lvsRow_No As GridViewRow In Me.grdBo.Rows
                Dim newCustomer As New MCUSTOMER

                ''''get values from Gridview '''''''
                mBO_UniqueID = lvsRow_No.Cells(2).Text : If mBO_UniqueID = "&nbsp;" Then mBO_UniqueID = ""
                mBO_THPREFIX = lvsRow_No.Cells(7).Text : If mBO_THPREFIX = "&nbsp;" Then mBO_THPREFIX = ""
                mBO_THFIRSTNAME = lvsRow_No.Cells(9).Text : If mBO_THFIRSTNAME = "&nbsp;" Then mBO_THFIRSTNAME = ""
                mBO_THMIDNAME = lvsRow_No.Cells(10).Text : If mBO_THMIDNAME = "&nbsp;" Then mBO_THMIDNAME = ""
                mBO_THLASTNAME = lvsRow_No.Cells(11).Text : If mBO_THLASTNAME = "&nbsp;" Then mBO_THLASTNAME = ""

                mBO_ENPREFIX = lvsRow_No.Cells(12).Text : If mBO_ENPREFIX = "&nbsp;" Then mBO_ENPREFIX = ""
                mBO_ENFIRSTNAME = lvsRow_No.Cells(14).Text : If mBO_ENFIRSTNAME = "&nbsp;" Then mBO_ENFIRSTNAME = ""
                mBO_ENMIDNAME = lvsRow_No.Cells(15).Text : If mBO_ENMIDNAME = "&nbsp;" Then mBO_ENMIDNAME = ""
                mBO_ENLASTNAME = lvsRow_No.Cells(16).Text : If mBO_ENLASTNAME = "&nbsp;" Then mBO_ENLASTNAME = ""

                mBO_Filter_Result = lvsRow_No.Cells(18).Text : If mBO_Filter_Result = "&nbsp;" Then mBO_Filter_Result = ""
                mBO_Risk_Level = lvsRow_No.Cells(19).Text : If mBO_Risk_Level = "&nbsp;" Then mBO_Risk_Level = ""

                lvsSQL = ""
                lvsSQL += "      SELECT THFIRSTNAME,                        "
                lvsSQL += "             THMIDNAME,                          "
                lvsSQL += "             THLASTNAME                          "
                lvsSQL += "        FROM MCUSTOMER                           "
                lvsSQL += "       WHERE UNIQUEID = '" & mBO_UniqueID & "'   "
                dtSmartCard = clsDatabase.QueryDataTable(lvsSQL)

                If (dtSmartCard.Rows.Count = 0) Then

                    Dim lvsrow As Integer
                    lvsrow += 1


                    CustSeq_BO = Gen_CusSeq(CInt(lvsrow))

                    '''''''LINQ Start here '''''''''''''
                    newCustomer.CUSTSEQ = CustSeq_BO
                    newCustomer.CUSTTYPE = lvsCustType
                    newCustomer.UNIQUEID = mBO_UniqueID.Trim

                    newCustomer.THPREFIX = mBO_THPREFIX.Trim
                    newCustomer.THFIRSTNAME = mBO_THFIRSTNAME.Trim
                    newCustomer.THMIDNAME = mBO_THMIDNAME.Trim
                    newCustomer.THLASTNAME = mBO_THLASTNAME.Trim

                    newCustomer.ENPREFIX = mBO_ENPREFIX.Trim
                    newCustomer.ENFIRSTNAME = mBO_ENFIRSTNAME.Trim
                    newCustomer.ENMIDNAME = mBO_ENMIDNAME.Trim
                    newCustomer.ENLASTNAME = mBO_ENLASTNAME.Trim

                    newCustomer.FILTER_RESULT = mBO_Filter_Result.Trim
                    newCustomer.RISK_LEVEL = mBO_Risk_Level.Trim
                    newCustomer.AMLCDD = mBO_Risk_Level.Trim

                    newCustomer.TRANTYPE = "2" '''''เป็น BO
                    newCustomer.UPDATEDATE = Now.ToShortDateString
                    newCustomer.UPDATEBY = clsSessionMenuRight.getUserName
                    newCustomer.BRANCHCODE = clsSessionMenuRight.getBranchCode
                    newCustomer.ZONECODE = clsSessionMenuRight.getZoneCode
                    newCustomer.DEPTCODE = clsSessionMenuRight.getDeptCode
                    newCustomer.ALLCODERIGHT = clsSessionMenuRight.getAllCodeRight
                    newCustomer.CREATEBY = clsSessionMenuRight.getUserName
                    newCustomer.CREATEDATE = Now.ToShortDateString
                    KYCEntity.AddToMCUSTOMER(newCustomer)

                End If

                ''''''''''''''''''''''''''''''''''''
            Next
            KYCEntity.SaveChanges()

        Catch ex As Exception
            Throw ex

        End Try


    End Sub

    Protected Sub Save_to_Cust_Family(ByVal key As Integer)

        Dim mFAM_Cif_No As String = ""
        Dim mFAM_UniqueID As String = ""
        Dim mFAM_PassportNo As String = ""

        Dim mFAM_OTH_ID_TYPE As String = ""
        Dim mFAM_OTH_ID_DESC As String = ""
        Dim mFAM_OTH_ID_NO As String = ""

        Dim mFAM_THPrefix As String = ""
        Dim mFAM_THPrefix_Desc As String = ""
        Dim mFAM_THFirstName As String = ""
        Dim mFAM_THMidName As String = ""
        Dim mFAM_THLastName As String = ""

        Dim mFAM_ENPrefix As String = ""
        Dim mFAM_ENPrefix_Desc As String = ""
        Dim mFAM_ENFirstName As String = ""
        Dim mFAM_ENMidName As String = ""
        Dim mFAM_ENLastName As String = ""
        Dim mFAM_Cust_Relation As String = ""

        Dim mFAM_Filter_Result As String = ""
        Dim mFAM_Risk_Level As String = ""
        Dim chActive As String = ""

        Dim lvsCustType As Integer = Session("KYC")
        '''''''''''''''''''''''

        Try

            Dim DeletedQuery = (From m In KYCEntity.MCUST_FAMILY
                               Where m.CUSTSEQ = key _
                              Select m).ToList

            If DeletedQuery.Count > 0 Then
                For i As Integer = 0 To DeletedQuery.Count - 1
                    KYCEntity.MCUST_FAMILY.DeleteObject(DeletedQuery(i))
                Next i
            End If
            ''''''''''''''''''''''

            For Each lvsRow_No As GridViewRow In Me.grdFamily.Rows
                Dim newCust_FAM As New MCUST_FAMILY

                ''''get values from Gridview '''''''
                mFAM_Cif_No = lvsRow_No.Cells(1).Text : If mFAM_Cif_No = "&nbsp;" Then mFAM_Cif_No = ""
                mFAM_UniqueID = lvsRow_No.Cells(2).Text : If mFAM_UniqueID = "&nbsp;" Then mFAM_UniqueID = ""
                mFAM_PassportNo = lvsRow_No.Cells(3).Text : If mFAM_PassportNo = "&nbsp;" Then mFAM_PassportNo = ""

                mFAM_OTH_ID_TYPE = lvsRow_No.Cells(4).Text : If mFAM_OTH_ID_TYPE = "&nbsp;" Then mFAM_OTH_ID_TYPE = ""
                mFAM_OTH_ID_DESC = lvsRow_No.Cells(5).Text : If mFAM_OTH_ID_DESC = "&nbsp;" Then mFAM_OTH_ID_DESC = ""
                mFAM_OTH_ID_NO = lvsRow_No.Cells(6).Text : If mFAM_OTH_ID_NO = "&nbsp;" Then mFAM_OTH_ID_NO = ""

                mFAM_THPrefix = lvsRow_No.Cells(7).Text : If mFAM_THPrefix = "&nbsp;" Then mFAM_THPrefix = ""
                mFAM_THPrefix_Desc = lvsRow_No.Cells(8).Text : If mFAM_THPrefix_Desc = "&nbsp;" Then mFAM_THPrefix_Desc = ""
                mFAM_THFirstName = lvsRow_No.Cells(9).Text : If mFAM_THFirstName = "&nbsp;" Then mFAM_THFirstName = ""
                mFAM_THMidName = lvsRow_No.Cells(10).Text : If mFAM_THMidName = "&nbsp;" Then mFAM_THMidName = ""
                mFAM_THLastName = lvsRow_No.Cells(11).Text : If mFAM_THLastName = "&nbsp;" Then mFAM_THLastName = ""

                mFAM_ENPrefix = lvsRow_No.Cells(12).Text : If mFAM_ENPrefix = "&nbsp;" Then mFAM_ENPrefix = ""
                mFAM_ENPrefix_Desc = lvsRow_No.Cells(13).Text : If mFAM_ENPrefix_Desc = "&nbsp;" Then mFAM_ENPrefix_Desc = ""
                mFAM_ENFirstName = lvsRow_No.Cells(14).Text : If mFAM_ENFirstName = "&nbsp;" Then mFAM_ENFirstName = ""
                mFAM_ENMidName = lvsRow_No.Cells(15).Text : If mFAM_ENMidName = "&nbsp;" Then mFAM_ENMidName = ""
                mFAM_ENLastName = lvsRow_No.Cells(16).Text : If mFAM_ENLastName = "&nbsp;" Then mFAM_ENLastName = ""

                mFAM_Cust_Relation = lvsRow_No.Cells(17).Text : If mFAM_Cust_Relation = "&nbsp;" Then mFAM_Cust_Relation = ""

                mFAM_Filter_Result = lvsRow_No.Cells(18).Text : If mFAM_Filter_Result = "&nbsp;" Then mFAM_Filter_Result = ""
                mFAM_Risk_Level = lvsRow_No.Cells(19).Text : If mFAM_Risk_Level = "&nbsp;" Then mFAM_Risk_Level = "1"

                If (CType(lvsRow_No.Cells(20).FindControl("chk_ACT_FAM_RELATE"), CheckBox).Checked = True) Then
                    chActive = "Y"
                Else
                    chActive = "N"
                End If

                ''''''''''''''''''''''''''''''''''''

                '''''''LINQ Start here '''''''''''''
                newCust_FAM.CUSTSEQ = key
                newCust_FAM.CUSTTYPE = Session("KYC")
                newCust_FAM.SEQ = lvsRow_No.RowIndex + 1
                newCust_FAM.CIF_NO = mFAM_Cif_No.Trim
                newCust_FAM.UNIQUEID = mFAM_UniqueID.Trim
                newCust_FAM.PASSPORT_NO = mFAM_PassportNo.Trim

                newCust_FAM.OTH_ID_TYPE = mFAM_OTH_ID_TYPE.Trim
                newCust_FAM.OTH_ID_DESC = mFAM_OTH_ID_DESC.Trim
                newCust_FAM.OTH_ID_NO = mFAM_OTH_ID_NO.Trim

                newCust_FAM.THPREFIX = mFAM_THPrefix.Trim
                newCust_FAM.THPREFIX_DESC = mFAM_THPrefix_Desc.Trim
                newCust_FAM.THFIRSTNAME = mFAM_THFirstName.Trim
                newCust_FAM.THMIDNAME = mFAM_THMidName.Trim
                newCust_FAM.THLASTNAME = mFAM_THLastName.Trim

                newCust_FAM.ENPREFIX = mFAM_ENPrefix.Trim
                newCust_FAM.ENPREFIX_DESC = mFAM_ENPrefix_Desc.Trim
                newCust_FAM.ENFIRSTNAME = mFAM_ENFirstName.Trim
                newCust_FAM.ENMIDNAME = mFAM_ENMidName.Trim
                newCust_FAM.ENLASTNAME = mFAM_ENLastName.Trim

                newCust_FAM.CUST_RELATION = mFAM_Cust_Relation.Trim
                newCust_FAM.FILTER_RESULT = mFAM_Filter_Result.Trim
                newCust_FAM.RISK_LEVEL = mFAM_Risk_Level

                newCust_FAM.ACTIVE = chActive
                newCust_FAM.CREATED_DATE = Now
                newCust_FAM.CREATED_BY = clsSessionMenuRight.getUserName
                KYCEntity.AddToMCUST_FAMILY(newCust_FAM)

            Next
            KYCEntity.SaveChanges()

        Catch ex As Exception
            Throw ex

        End Try



    End Sub

    Protected Sub Save_to_Cust_SanctList(ByVal key As Integer)

        Dim chActive As String = ""
        Dim mENTITY_ID As String = ""
        Dim mFAM_UniqueID As String = ""
        Dim mFIRSTNAME_E As String = ""
        Dim mMIDDLE_NAME_E As String = ""
        Dim mSURNAME_E As String = ""
        Dim mFullName As String = ""
        Dim mFIRST_NAME As String = ""
        Dim mMID_NAME As String = ""
        Dim mSURNAME As String = ""
        Dim mORIGINAL_SCRIPT_NAME As String = ""
        Dim mBIRTHINFO_DATE As String = ""
        Dim mCOUNTRY_DESC As String = ""
        Dim mDATASOURCE As String = ""
        Dim mSANC_UPDATE_DATE As String = ""



        Dim lvsCustType As Integer = Session("KYC")
        '''''''''''''''''''''''

        Try

            Dim DeletedQuery = (From m In KYCEntity.MCUST_SANC_LIST
                               Where m.CUSTSEQ = key _
                              Select m).ToList

            If DeletedQuery.Count > 0 Then
                For i As Integer = 0 To DeletedQuery.Count - 1
                    KYCEntity.MCUST_SANC_LIST.DeleteObject(DeletedQuery(i))
                Next i
            End If
            ''''''''''''''''''''''

            For Each lvsRow_No As GridViewRow In Me.grdList.Rows
                Dim newCust_Sanct As New MCUST_SANC_LIST

                ''''get values from Gridview '''''''

                Dim lvsCHKBOX = CType(lvsRow_No.FindControl("chkList"), CheckBox).Checked
                If lvsCHKBOX Then
                    chActive = "Y"
                Else
                    chActive = "N"
                End If


                mENTITY_ID = lvsRow_No.Cells(1).Text : If mENTITY_ID = "&nbsp;" Then mENTITY_ID = ""
                mFAM_UniqueID = lvsRow_No.Cells(2).Text : If mFAM_UniqueID = "&nbsp;" Then mFAM_UniqueID = ""
                mFIRSTNAME_E = lvsRow_No.Cells(3).Text : If mFIRSTNAME_E = "&nbsp;" Then mFIRSTNAME_E = ""
                mMIDDLE_NAME_E = lvsRow_No.Cells(4).Text : If mMIDDLE_NAME_E = "&nbsp;" Then mMIDDLE_NAME_E = ""
                mSURNAME_E = lvsRow_No.Cells(5).Text : If mSURNAME_E = "&nbsp;" Then mSURNAME_E = ""
                mFullName = lvsRow_No.Cells(6).Text : If mFullName = "&nbsp;" Then mFullName = ""
                mFIRST_NAME = lvsRow_No.Cells(7).Text : If mFIRST_NAME = "&nbsp;" Then mFIRST_NAME = ""
                mMID_NAME = lvsRow_No.Cells(8).Text : If mMID_NAME = "&nbsp;" Then mMID_NAME = ""
                mSURNAME = lvsRow_No.Cells(9).Text : If mSURNAME = "&nbsp;" Then mSURNAME = ""
                mORIGINAL_SCRIPT_NAME = lvsRow_No.Cells(10).Text : If mORIGINAL_SCRIPT_NAME = "&nbsp;" Then mORIGINAL_SCRIPT_NAME = ""
                mBIRTHINFO_DATE = lvsRow_No.Cells(11).Text : If mBIRTHINFO_DATE = "&nbsp;" Then mBIRTHINFO_DATE = ""
                mCOUNTRY_DESC = lvsRow_No.Cells(12).Text : If mCOUNTRY_DESC = "&nbsp;" Then mCOUNTRY_DESC = ""
                mDATASOURCE = lvsRow_No.Cells(13).Text : If mDATASOURCE = "&nbsp;" Then mDATASOURCE = ""

                ''''Use Findcontrol method
                Dim lbdate = CType(lvsRow_No.FindControl("lblActiveDate"), Label).Text
                mSANC_UPDATE_DATE = lbdate : If mSANC_UPDATE_DATE = "&nbsp;" Then mSANC_UPDATE_DATE = ""
                ''''''''''''''''''''''''''''''''''''

                '''''''LINQ Start here '''''''''''''
                newCust_Sanct.CUSTSEQ = key
                newCust_Sanct.CUSTTYPE = Session("KYC")
                newCust_Sanct.SEQ = lvsRow_No.RowIndex + 1
                newCust_Sanct.CHKLIST = chActive
                newCust_Sanct.UNIQUEID = mFAM_UniqueID.Trim
                newCust_Sanct.FIRSTNAME_E = mFIRSTNAME_E.Trim
                newCust_Sanct.MIDDLE_NAME_E = mMIDDLE_NAME_E.Trim
                newCust_Sanct.SURNAME_E = mSURNAME_E.Trim
                newCust_Sanct.FULLNAME = mFullName.Trim
                newCust_Sanct.FIRST_NAME = mFIRST_NAME.Trim
                newCust_Sanct.MIDDLE_NAME = mMID_NAME.Trim
                newCust_Sanct.SURNAME = mSURNAME.Trim
                newCust_Sanct.ORIGINAL_SCRIPT_NAME = mORIGINAL_SCRIPT_NAME.Trim
                newCust_Sanct.BIRTHINFO_DATE = mBIRTHINFO_DATE.Trim
                newCust_Sanct.COUNTRY_DESC = mCOUNTRY_DESC.Trim
                newCust_Sanct.DATASOURCE = mDATASOURCE.Trim
                newCust_Sanct.ENTITY_ID = mENTITY_ID.Trim
                newCust_Sanct.SANC_UPDATE_DATE = mSANC_UPDATE_DATE.Trim
                '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                newCust_Sanct.CREATED_DATE = Now
                newCust_Sanct.CREATED_BY = clsSessionMenuRight.getUserName
                '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                KYCEntity.AddToMCUST_SANC_LIST(newCust_Sanct)

            Next
            KYCEntity.SaveChanges()

        Catch ex As Exception
            Throw ex

        End Try



    End Sub

    Protected Sub Save_to_Cust_Name(ByVal key As Integer)


        Dim mUNIQUEID As String = ""
        Dim mPASSPORT_NO As String = ""

        Dim mTHPREFIX As String = ""
        Dim mTHPREFIX_DESC As String = ""
        Dim mTHFIRSTNAME As String = ""
        Dim mTHMIDNAME As String = ""
        Dim mTHLASTNAME As String = ""

        Dim mENPREFIX As String = ""
        Dim mENPREFIX_DESC As String = ""
        Dim mENFIRSTNAME As String = ""
        Dim mENMIDNAME As String = ""
        Dim mENLASTNAME As String = ""

        Dim mUSER_CREATED_DATE As String = ""
        Dim mUSER_CREATED_BY As String = ""
        Dim chActive As String = ""
        Dim lvsCustType As Integer = Session("KYC")
        '''''''''''''''''''''''

        Try

            Dim DeletedQuery = (From m In KYCEntity.MCUST_NAME
                               Where m.CUSTSEQ = key _
                              Select m).ToList

            If DeletedQuery.Count > 0 Then
                For i As Integer = 0 To DeletedQuery.Count - 1
                    KYCEntity.MCUST_NAME.DeleteObject(DeletedQuery(i))
                Next i
            End If
            ''''''''''''''''''''''
            For Each lvsRow_No As GridViewRow In Me.grdCust_NAME.Rows
                Dim newCust_Name As New MCUST_NAME

                ''''get values from Gridview '''''''


                mUNIQUEID = lvsRow_No.Cells(1).Text : If mUNIQUEID = "&nbsp;" Then mUNIQUEID = ""
                mPASSPORT_NO = lvsRow_No.Cells(2).Text : If mPASSPORT_NO = "&nbsp;" Then mPASSPORT_NO = ""

                mTHPREFIX = lvsRow_No.Cells(3).Text : If mTHPREFIX = "&nbsp;" Then mTHPREFIX = ""
                mTHPREFIX_DESC = lvsRow_No.Cells(4).Text : If mTHPREFIX_DESC = "&nbsp;" Then mTHPREFIX_DESC = ""
                mTHFIRSTNAME = lvsRow_No.Cells(5).Text : If mTHFIRSTNAME = "&nbsp;" Then mTHFIRSTNAME = ""
                mTHMIDNAME = lvsRow_No.Cells(6).Text : If mTHMIDNAME = "&nbsp;" Then mTHMIDNAME = ""
                mTHLASTNAME = lvsRow_No.Cells(7).Text : If mTHLASTNAME = "&nbsp;" Then mTHLASTNAME = ""


                mENPREFIX = lvsRow_No.Cells(8).Text : If mENPREFIX = "&nbsp;" Then mENPREFIX = ""
                mENPREFIX_DESC = lvsRow_No.Cells(9).Text : If mENPREFIX_DESC = "&nbsp;" Then mENPREFIX_DESC = ""
                mENFIRSTNAME = lvsRow_No.Cells(10).Text : If mENFIRSTNAME = "&nbsp;" Then mENFIRSTNAME = ""
                mENMIDNAME = lvsRow_No.Cells(11).Text : If mENMIDNAME = "&nbsp;" Then mENMIDNAME = ""
                mENLASTNAME = lvsRow_No.Cells(12).Text : If mENLASTNAME = "&nbsp;" Then mENLASTNAME = ""

                mUSER_CREATED_DATE = lvsRow_No.Cells(13).Text : If mUSER_CREATED_DATE = "&nbsp;" Then mUSER_CREATED_DATE = ""
                mUSER_CREATED_BY = lvsRow_No.Cells(14).Text : If mUSER_CREATED_BY = "&nbsp;" Then mUSER_CREATED_BY = ""
                If (CType(lvsRow_No.Cells(15).FindControl("chkACT_CUST_NAME"), CheckBox).Checked = True) Then
                    chActive = "Y"
                Else
                    chActive = "N"
                End If

                ''''''''''''''''''''''''''''''''''''

                '''''''LINQ Start here '''''''''''''
                newCust_Name.CUSTSEQ = key
                newCust_Name.CUSTTYPE = Session("KYC")
                newCust_Name.SEQ = lvsRow_No.RowIndex + 1
                newCust_Name.UNIQUEID = mUNIQUEID.Trim
                newCust_Name.PASSPORT_NO = mPASSPORT_NO.Trim

                newCust_Name.THPREFIX = mTHPREFIX.Trim
                newCust_Name.THPREFIX_DESC = mTHPREFIX_DESC.Trim

                newCust_Name.THFIRSTNAME = mTHFIRSTNAME.Trim
                newCust_Name.THMIDNAME = mTHMIDNAME.Trim
                newCust_Name.THLASTNAME = mTHLASTNAME.Trim

                newCust_Name.ENPREFIX = mENPREFIX.Trim
                newCust_Name.ENPREFIX_DESC = mENPREFIX_DESC.Trim
                newCust_Name.ENFIRSTNAME = mENFIRSTNAME.Trim
                newCust_Name.ENMIDNAME = mENMIDNAME.Trim
                newCust_Name.ENLASTNAME = mENLASTNAME.Trim
                newCust_Name.USER_CREATED_DATE = mUSER_CREATED_DATE.Trim
                newCust_Name.USER_CREATED_BY = mUSER_CREATED_BY.Trim

                newCust_Name.ACTIVE = chActive
                newCust_Name.CREATED_DATE = Now
                newCust_Name.CREATED_BY = clsSessionMenuRight.getUserName
                KYCEntity.AddToMCUST_NAME(newCust_Name)

            Next
            KYCEntity.SaveChanges()

        Catch ex As Exception
            Throw ex

        End Try


    End Sub


    Protected Sub Save_to_Cust_Occupation(ByVal key As Integer)

        Dim mMainOcc_Desc As String = ""
        Dim mMainOcc_Code As String = ""
        Dim mSubOcc_Desc As String = ""
        Dim mMainOcc_RemarkT As String = ""
        Dim mSubOcc_Code As String = ""
        Dim mPosition As String = ""
        Dim chActive As String = ""
        Dim mRisk As String = ""
        Dim lvsCustType As Integer = Session("KYC")

        '''''''''''''''''''''''

        Try

            Dim DeletedQuery = (From m In KYCEntity.MCUST_OCCUPATION
                               Where m.CUSTSEQ = key _
                              Select m).ToList

            If DeletedQuery.Count > 0 Then
                For i As Integer = 0 To DeletedQuery.Count - 1
                    KYCEntity.MCUST_OCCUPATION.DeleteObject(DeletedQuery(i))
                Next i
            End If
            ''''''''''''''''''''''
            For Each lvsRow_No As GridViewRow In Me.grdOcc.Rows
                Dim newCust_Occ As New MCUST_OCCUPATION

                ''''get values from Gridview '''''''
                mMainOcc_Desc = lvsRow_No.Cells(1).Text : If mMainOcc_Desc = "&nbsp;" Then mMainOcc_Desc = ""
                mMainOcc_Code = lvsRow_No.Cells(2).Text : If mMainOcc_Code = "&nbsp;" Then mMainOcc_Code = ""
                mSubOcc_Desc = lvsRow_No.Cells(3).Text : If mSubOcc_Desc = "&nbsp;" Then mSubOcc_Desc = ""
                mMainOcc_RemarkT = lvsRow_No.Cells(4).Text : If mMainOcc_RemarkT = "&nbsp;" Then mMainOcc_RemarkT = ""
                mSubOcc_Code = lvsRow_No.Cells(5).Text : If mSubOcc_Code = "&nbsp;" Then mSubOcc_Code = ""
                mPosition = lvsRow_No.Cells(6).Text : If mPosition = "&nbsp;" Then mPosition = ""
                mRisk = lvsRow_No.Cells(7).Text : If mRisk = "&nbsp;" Then mRisk = ""

                If (CType(lvsRow_No.Cells(8).FindControl("chkACT_OCCUPATION"), CheckBox).Checked = True) Then
                    chActive = "Y"
                Else
                    chActive = "N"
                End If

                ''''''''''''''''''''''''''''''''''''

                '''''''LINQ Start here '''''''''''''
                newCust_Occ.CUSTSEQ = key
                newCust_Occ.CUSTTYPE = Session("KYC")
                newCust_Occ.SEQ = lvsRow_No.RowIndex + 1
                newCust_Occ.OCC_DESC = mMainOcc_Desc.Trim
                newCust_Occ.OCCCODE = mMainOcc_Code.Trim
                newCust_Occ.REMARK_T = mMainOcc_RemarkT.Trim
                newCust_Occ.OCC_SUB_DESC = mSubOcc_Desc.Trim
                newCust_Occ.OCCCODE_SUB = mSubOcc_Code.Trim
                newCust_Occ.POSITION = mPosition.Trim
                newCust_Occ.RISK = mRisk.Trim
                newCust_Occ.ACTIVE = chActive
                newCust_Occ.CREATED_DATE = Now
                newCust_Occ.CREATED_BY = clsSessionMenuRight.getUserName
                KYCEntity.AddToMCUST_OCCUPATION(newCust_Occ)
            Next
            KYCEntity.SaveChanges()

        Catch ex As Exception
            Throw ex

        End Try


    End Sub

    Protected Sub Save_to_Cust_nation(ByVal key As Integer)

        Dim mNationName As String = ""
        Dim mNationID As String = ""
        Dim mNAT_RISK As String = ""
        Dim chActive As String = ""
        Dim lvsCustType As Integer = Session("KYC")
        '''''''''''''''''''''''

        Try

            Dim DeletedQuery = (From m In KYCEntity.MCUST_NATION
                               Where m.CUSTSEQ = key _
                              Select m).ToList

            If DeletedQuery.Count > 0 Then
                For i As Integer = 0 To DeletedQuery.Count - 1
                    KYCEntity.MCUST_NATION.DeleteObject(DeletedQuery(i))
                Next i
            End If
            ''''''''''''''''''''''
            For Each rowID As GridViewRow In grdNaiton.Rows
                Dim newCust_Nation As New MCUST_NATION

                ''''get values from Gridview '''''''
                mNationName = rowID.Cells(1).Text : If mNationName = "&nbsp;" Then mNationName = ""
                mNationID = rowID.Cells(2).Text : If mNationID = "&nbsp;" Then mNationID = ""
                mNAT_RISK = rowID.Cells(3).Text : If mNAT_RISK = "&nbsp;" Then mNAT_RISK = 0

                If (CType(rowID.Cells(4).FindControl("chActive"), CheckBox).Checked = True) Then
                    chActive = "Y"
                Else
                    chActive = "N"
                End If


                ''''''''''''''''''''''''''''''''''''

                '''''''LINQ Start here ''''''''''''''
                newCust_Nation.CUSTSEQ = key
                newCust_Nation.CUSTTYPE = Session("KYC")
                newCust_Nation.SEQ = rowID.RowIndex + 1
                newCust_Nation.NATIONALITY = mNationID
                newCust_Nation.NATION_NAME = mNationName
                newCust_Nation.RISK_LEVEL = mNAT_RISK
                newCust_Nation.ACTIVE = chActive
                newCust_Nation.CREATED_DATE = Now
                newCust_Nation.CREATED_BY = clsSessionMenuRight.getUserName
                KYCEntity.AddToMCUST_NATION(newCust_Nation)
            Next
            KYCEntity.SaveChanges()
        Catch ex As Exception
            Throw ex
            'Catch ex As System.Data.SqlClient.SqlException
            '    Dim lvsERROR As String = ex.Message.ToString
            '    ScriptManager.RegisterStartupScript(Me, Me.GetType(), "clientScript", "alert('" & lvsERROR & "')", True)
        End Try




    End Sub

    Protected Sub Save_to_Cust_Reason(ByVal key As Integer)

        Dim mUser_Created_Date As String = ""
        Dim mUser_Created_By As String = ""
        Dim mUser_Reason As String = ""
        Dim chActive As String = ""
        Dim lvsCustType As Integer = Session("KYC")
        '''''''''''''''''''''''

        Try

            Dim DeletedQuery = (From m In KYCEntity.MCUST_REASON
                               Where m.CUSTSEQ = key _
                              Select m).ToList

            If DeletedQuery.Count > 0 Then
                For i As Integer = 0 To DeletedQuery.Count - 1
                    KYCEntity.MCUST_REASON.DeleteObject(DeletedQuery(i))
                Next i
            End If
            ''''''''''''''''''''''
            For Each rowID As GridViewRow In grdReason.Rows
                Dim newCust_Reason As New MCUST_REASON

                ''''get values from Gridview '''''''
                mUser_Reason = rowID.Cells(1).Text : If mUser_Reason = "&nbsp;" Then mUser_Reason = ""
                mUser_Created_Date = rowID.Cells(2).Text : If mUser_Created_Date = "&nbsp;" Then mUser_Created_Date = ""
                mUser_Created_By = rowID.Cells(3).Text : If mUser_Created_By = "&nbsp;" Then mUser_Created_By = ""
                If (CType(rowID.Cells(4).FindControl("chk_ACT_REASON"), CheckBox).Checked = True) Then
                    chActive = "Y"
                Else
                    chActive = "N"
                End If


                ''''''''''''''''''''''''''''''''''''

                '''''''LINQ Start here ''''''''''''''
                newCust_Reason.CUSTSEQ = key
                newCust_Reason.CUSTTYPE = Session("KYC")
                newCust_Reason.SEQ = rowID.RowIndex + 1
                newCust_Reason.USER_CREATED_DATE = mUser_Created_Date
                newCust_Reason.USER_CREATED_BY = mUser_Created_By
                newCust_Reason.REASONS = Mid(mUser_Reason, 1, 150)
                newCust_Reason.ACTIVE = chActive
                newCust_Reason.CREATED_DATE = Now
                newCust_Reason.CREATED_BY = clsSessionMenuRight.getUserName
                KYCEntity.AddToMCUST_REASON(newCust_Reason)
            Next
            KYCEntity.SaveChanges()
        Catch ex As Exception
            Throw ex
            'Catch ex As System.Data.SqlClient.SqlException
            '    Dim lvsERROR As String = ex.Message.ToString
            '    ScriptManager.RegisterStartupScript(Me, Me.GetType(), "clientScript", "alert('" & lvsERROR & "')", True)
        End Try




    End Sub

    Protected Sub Save_to_Cust_Income_source(ByVal key As Integer)

        Dim mCountryName As String = ""
        Dim mNationCode As String = ""
        Dim mCountryNameTH As String = ""
        Dim mINC_RISK As String = ""
        Dim chActive As String = ""
        Dim lvsCustType As Integer = Session("KYC")
        '''''''''''''''''''''''

        Try

            Dim DeletedQuery = (From m In KYCEntity.MCUST_INCOME_SOURCE
                               Where m.CUSTSEQ = key _
                              Select m).ToList

            If DeletedQuery.Count > 0 Then
                For i As Integer = 0 To DeletedQuery.Count - 1
                    KYCEntity.MCUST_INCOME_SOURCE.DeleteObject(DeletedQuery(i))
                Next i
            End If
            ''''''''''''''''''''''
            For Each rowIncome As GridViewRow In Me.grdIncome.Rows
                Dim newCust_Income_Source As New MCUST_INCOME_SOURCE

                ''''get values from Gridview '''''''
                mCountryName = rowIncome.Cells(1).Text : If mCountryName = "&nbsp;" Then mCountryName = ""
                mNationCode = rowIncome.Cells(2).Text : If mNationCode = "&nbsp;" Then mNationCode = ""
                mCountryNameTH = rowIncome.Cells(3).Text : If mCountryNameTH = "&nbsp;" Then mCountryNameTH = ""

                mINC_RISK = rowIncome.Cells(4).Text : If mINC_RISK = "&nbsp;" Then mINC_RISK = 0
                If (CType(rowIncome.Cells(5).FindControl("chk_ACT_INC_SOURCE"), CheckBox).Checked = True) Then
                    chActive = "Y"
                Else
                    chActive = "N"
                End If

                ''''''''''''''''''''''''''''''''''''

                '''''''LINQ Start here ''''''''''''''
                newCust_Income_Source.CUSTSEQ = key
                newCust_Income_Source.CUSTTYPE = Session("KYC")
                newCust_Income_Source.SEQ = rowIncome.RowIndex + 1
                newCust_Income_Source.NATIONCODE = mNationCode
                newCust_Income_Source.COUNTYNAME = mCountryName
                newCust_Income_Source.COUNTYNAMETH = mCountryNameTH
                newCust_Income_Source.RISK_LEVEL = mINC_RISK
                newCust_Income_Source.ACTIVE = chActive
                newCust_Income_Source.CREATED_DATE = Now
                newCust_Income_Source.CREATED_BY = clsSessionMenuRight.getUserName
                KYCEntity.AddToMCUST_INCOME_SOURCE(newCust_Income_Source)
            Next
            KYCEntity.SaveChanges()
        Catch ex As Exception
            Throw ex
            'Catch ex As System.Data.SqlClient.SqlException
            '    Dim lvsERROR As String = ex.Message.ToString
            '    ScriptManager.RegisterStartupScript(Me, Me.GetType(), "clientScript", "alert('" & lvsERROR & "')", True)
        End Try




    End Sub

    Protected Sub Save_to_Cust_nation_Transaction(ByVal key As Integer)


        Dim mNationName As String = ""
        Dim mNationID As String = ""
        Dim chActive As String = ""
        Dim lvsCustType As Integer = Session("KYC")
        '''''''''''''''''''''''
        clsDatabase = New clsDatabase
        KYCEntity = New KYCEntities
        KYCEntity.Connection.Open()
        Using transaction As System.Data.Common.DbTransaction = KYCEntity.Connection.BeginTransaction()

            Try

                Dim DeletedQuery = (From m In KYCEntity.MCUST_NATION
                                   Where m.CUSTSEQ = key _
                                  Select m).ToList

                If DeletedQuery.Count > 0 Then
                    For i As Integer = 0 To DeletedQuery.Count - 1
                        KYCEntity.MCUST_NATION.DeleteObject(DeletedQuery(i))
                    Next i
                End If
                ''''''''''''''''''''''
                For Each rowID As GridViewRow In grdNaiton.Rows
                    Dim newCust_Nation As New MCUST_NATION

                    ''''get values from Gridview '''''''
                    mNationName = rowID.Cells(1).Text : If mNationName = "&nbsp;" Then mNationName = ""
                    mNationID = rowID.Cells(2).Text : If mNationID = "&nbsp;" Then mNationID = ""


                    If (CType(rowID.Cells(3).FindControl("chActive"), CheckBox).Checked = True) Then
                        chActive = "Y"
                    Else
                        chActive = "N"
                    End If


                    ''''''''''''''''''''''''''''''''''''

                    '''''''LINQ Start here ''''''''''''''
                    newCust_Nation.CUSTSEQ = key
                    newCust_Nation.CUSTTYPE = Session("KYC")
                    newCust_Nation.SEQ = rowID.RowIndex + 1
                    newCust_Nation.NATIONALITY = mNationID
                    newCust_Nation.NATION_NAME = mNationName
                    newCust_Nation.ACTIVE = chActive
                    newCust_Nation.CREATED_DATE = Now
                    newCust_Nation.CREATED_BY = clsSessionMenuRight.getUserName

                    KYCEntity.AddToMCUST_NATION(newCust_Nation)
                Next
                transaction.Commit()

            Catch ex As System.Data.SqlClient.SqlException
                Dim lvsERROR As String = ex.Message.ToString
                ScriptManager.RegisterStartupScript(Me, Me.GetType(), "clientScript", "alert('" & lvsERROR & "')", True)
                transaction.Rollback()

            End Try

        End Using

        KYCEntity.SaveChanges()
        KYCEntity = Nothing
        clsDatabase = Nothing


    End Sub

    Protected Sub btAddSanct_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btAddSanct.Click
        'Dim dRow As DataRow

        'If (Session("PopSanc") Is Nothing) Then
        '    dtSanc.Columns.Add(New DataColumn("SANID"))
        '    dtSanc.Columns.Add(New DataColumn("PASSPORT"))
        '    dtSanc.Columns.Add(New DataColumn("NAME_TH"))
        '    dtSanc.Columns.Add(New DataColumn("NAME_EN"))
        '    dtSanc.Columns.Add(New DataColumn("DATA_FROM"))
        '    dtSanc.Columns.Add(New DataColumn("UPDATE_DATE"))
        '    dtSanc.Columns.Add(New DataColumn("ACTIVE"))
        'Else
        '    dtNation = Session("PopSanc")
        'End If
        'dRow = dtSanc.NewRow()
        'dRow("SANID") = txtUniqueID.Text
        'dRow("PASSPORT") = "" 'เอาค่าอะไรมาใส่ว๊ะ...
        'dRow("NAME_TH") = txtNameTh1.Text
        'dRow("NAME_EN") = txtNameEn1.Text
        'dRow("DATA_FROM") = ddlSanctDataFrom.Text
        'dRow("UPDATE_DATE") = Now()
        'dRow("ACTIVE") = True
        'dtSanc.Rows.Add(dRow)
        'dtSanc.AcceptChanges()

        ''now bind datatable to gridview... 
        'grdSanc.DataSource = dtSanc
        'grdSanc.DataBind()
        'Session("PopSanc") = dtSanc
    End Sub

    Protected Sub btDelSanct_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btDelSanct.Click
        Try

            Dim index As Integer = grdSanc.SelectedIndex
            If index = -1 Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('ต้องเลือกรายการที่ต้องการลบก่อน')", True)
            Else

                Me.lblAuthor_Req_SancList.Text = "Y"
            End If

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Page, _
                                                            Page.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Function Validate_Occupation() As Boolean
        Validate_Occupation = False

        If CInt(Me.lblCount_OCC.Text) = 10 Then
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage",
                                                "window.alert('ระบบอนุญาติให้ป้อนข้อมูลอาชีพได้ไม่เกิน 10 อาขีพ');", True)
            ddlOccupation1.Focus()
            Exit Function
        End If


        If ddlOccupation1.SelectedIndex = 0 Then
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ต้องทำการเลือกข้อมูลให้ครบถ้วนก่อน');", True)
            ddlOccupation1.Focus()
            Exit Function
        End If

        If ddlOccupation4.SelectedIndex = 0 Then
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ต้องทำการเลือกข้อมูลให้ครบถ้วนก่อน');", True)
            ddlOccupation4.Focus()
            Exit Function
        End If

        ''''''''Validate ข้อมูลซ้ำ''''''''''''''''''
        Dim mOccupation1 As String = ""
        Dim mOccupation2 As String = ""
        For Each rowFromGrid As GridViewRow In Me.grdOcc.Rows

            mOccupation1 = rowFromGrid.Cells(1).Text
            mOccupation2 = rowFromGrid.Cells(4).Text

            If mOccupation1 & mOccupation2 = ddlOccupation1.SelectedItem.Text & Me.ddlOccupation4.SelectedItem.Text Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ข้อมูลซ้ำ ! กรูณาเลือกอาชีพอื่น');", True)
                ddlOccupation1.Focus()
                Exit Function
            End If

        Next
        '''''''''''''''''''''''''''''

        Validate_Occupation = True
    End Function

    Function Validate_Income() As Boolean
        Validate_Income = False

        ''''''''Validate ข้อมูลซ้ำ''''''''''''''''''
        Dim mIncome As String = ""
        For Each rowIncome As GridViewRow In grdIncome.Rows
            mIncome = rowIncome.Cells(1).Text
            If mIncome = ddlIncomeSource1.SelectedItem.Text Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ข้อมูลซ้ำ ! กรูณาเลือกแหล่งที่มาของรายได้อื่น');", True)
                ddlIncomeSource1.Focus()
                Exit Function
            End If

        Next
        '''''''''''''''''''''''''''''
        Validate_Income = True
    End Function

    Function Validate_Reason() As Boolean
        Validate_Reason = False
        If clsValid.CheckNull(Me.txtReasonApp) = False Then Exit Function
        Validate_Reason = True
    End Function

    Sub Delete_gridRow_grdReason()
        Try

            Dim index As Integer = grdReason.SelectedIndex
            If index = -1 Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('ต้องเลือกข้อมูลเหตุผลที่ต้องการลบก่อน')", True)
            Else
                'check session of data table
                If Not (Session("PopReason") Is Nothing) Then
                    Me.dtReason = Session("PopReason")
                End If
                ''''remove row at...
                dtReason.Rows.RemoveAt(index)
                dtReason.AcceptChanges()

                ''''bind data again
                grdReason.DataSource = dtReason
                grdReason.DataBind()
                ''''Number of Rows''''''''''''''''''''''''''''''
                Me.lblCount_Reason.Text = Me.dtReason.Rows.Count
                ''''''''''''''''''''''''''''''''''''''''''''''''
                ''''deselect '''''''''''''''
                grdReason.SelectedIndex = -1
                '''''''''''''''''''''''''''''
            End If

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Page, _
                                                            Page.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub btDelReason_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btDelReason.Click
        Delete_gridRow_grdReason()
    End Sub

    Function Validate_Acct_Family_Concern() As Boolean

        clsCheckID = New clsCheckID

        Validate_Acct_Family_Concern = False


        If Me.txtFAM_UNIQUEID.Text = "" And Me.txtFAM_PASSPORT_NO.Text = "" Then
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage",
                                                "window.alert('กรุณาป้อนเลขที่บัตรประชาขนหรือเลขที่หนังสือเดินทางให้ถูกต้อง');", True)
            txtFAM_UNIQUEID.Focus()
            Exit Function
        ElseIf Me.txtFAM_UNIQUEID.Text <> "" Then
            If Not (clsCheckID.chkIDcard(txtFAM_UNIQUEID.Text.Trim)) Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage",
                                                    "window.alert('เลขที่บัตรประชาชนไม่ถูกต้อง');", True)
                Exit Function
                txtFAM_UNIQUEID.Focus()
            End If
        ElseIf Me.txtFAM_UNIQUEID.Text <> "" And Me.txtFAM_PASSPORT_NO.Text <> "" Then
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage",
                                                "window.alert('เลขที่บัตรประชาชนไม่ถูกต้อง');", True)
            Exit Function
            txtFAM_UNIQUEID.Focus()
        End If

        ''''''''''''validate ข้อมูลซ้ำ''''''''''''
        Dim mFamIdCard As String = ""
        For Each rowNumber As GridViewRow In grdFamily.Rows

            mFamIdCard = rowNumber.Cells(2).Text

            If mFamIdCard.Trim = Me.txtFAM_UNIQUEID.Text.Trim Then
                ScriptManager.RegisterStartupScript(Page,
                                                    Page.GetType(), "alertMessage",
                                                    "window.alert('ข้อมูลซ้ำ ! กรูณาป้อนเลขที่บัตรประชาชนใหม่');", True)
                txtFAM_UNIQUEID.Focus()
                Exit Function
            End If

        Next
        ''''''''''''''''''''''''''''''''''''''

        If clsValid.CheckNull(Me.txtFAM_FIRSTNAME_TH) = False Then Exit Function
        If clsValid.CheckNull(Me.txtFAM_LASTNAME_TH) = False Then Exit Function

        'If clsValid.CheckNull(Me.txtFAM_ENFIRSTNAME) = False Then Exit Function
        'If clsValid.CheckNull(Me.txtFAM_ENLASTNAME) = False Then Exit Function


        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        '''''หาว่าข้อมูลที่ป้อนมีชื่อไม่ตรงกับใน Mcustomer '''''''''''''''''''''''
        Dim dtSmartCard As DataTable = New DataTable

        Dim lvsSmartCard_FirstName_TH As String = ""
        Dim lvsSmartCard_LastName_TH As String = ""

        lvsSQL = ""
        lvsSQL += "      SELECT THFIRSTNAME,                                "
        lvsSQL += "             THMIDNAME,                                  "
        lvsSQL += "             THLASTNAME,                                 "
        lvsSQL += "             ENFIRSTNAME,                                "
        lvsSQL += "             ENMIDNAME,                                  "
        lvsSQL += "             ENLASTNAME                                  "
        lvsSQL += "        FROM MCUSTOMER                                   "
        lvsSQL += "       WHERE UNIQUEID = '" & Me.txtFAM_UNIQUEID.Text & "'"
        dtSmartCard = clsDatabase.QueryDataTable(lvsSQL)

        If (dtSmartCard.Rows.Count <> 0) Then

            If Not IsDBNull(dtSmartCard.Rows(0)("THFIRSTNAME")) Then lvsSmartCard_FirstName_TH = dtSmartCard.Rows(0)("THFIRSTNAME")
            If Not IsDBNull(dtSmartCard.Rows(0)("THLASTNAME")) Then lvsSmartCard_LastName_TH = dtSmartCard.Rows(0)("THLASTNAME")

            If lvsSmartCard_FirstName_TH.Trim & lvsSmartCard_LastName_TH.Trim _
                <> Me.txtFAM_FIRSTNAME_TH.Text.Trim & Me.txtFAM_LASTNAME_TH.Text.Trim Then

                Dim lvsAleart As String = "เลขที่บัตรประชาชนที่ป้อนมี-ชื่อหรือนามสกุล-ไม่ตรงกับข้อมูลจากระบบ KYC ชื่อ = " _
                                          & lvsSmartCard_FirstName_TH & " นามสกุล = " _
                                          & lvsSmartCard_LastName_TH

                ScriptManager.RegisterStartupScript(Page, Page.GetType(),
                            "alertMessage",
                            "window.alert('" & lvsAleart & "');", True)

                Exit Function
                Me.txtFAM_FIRSTNAME_TH.Focus()

            End If

        End If
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

        If Me.lblFAM_FILTER_RESULT.Text = "" Then
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ต้องทำการตรวจกรองรายชือก่อน');", True)
            Exit Function
            lblFAM_FILTER_RESULT.Focus()
        End If


        Validate_Acct_Family_Concern = True
    End Function

    Function Validate_Potician_Concern() As Boolean
        Validate_Potician_Concern = False
        If clsValid.CheckNull(Me.txtPOLITIC_RELATION) = False Then Exit Function
        If clsValid.CheckNull(Me.txtPOLITIC_POST_CONC) = False Then Exit Function
        If clsValid.CheckNull(Me.txtTHFIRSTNAME) = False Then Exit Function
        If clsValid.CheckNull(Me.txtTHLASTNAME) = False Then Exit Function
        Validate_Potician_Concern = True
    End Function

    Function Validate_Acct_BO_Delete() As Boolean

        clsCheckID = New clsCheckID
        Validate_Acct_BO_Delete = False

        If Me.lblBO_uniqueID.Text = "" Then Exit Function
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        Dim dtBO_UNIQUE As DataTable = New DataTable
        Dim lvsACCOUNTNO As String = ""

        lvsSQL = ""
        lvsSQL += "      SELECT ACCOUNTNO                                   "
        lvsSQL += "        FROM kycadmin.MCUST_BO_ACCT                      "
        lvsSQL += "       WHERE UNIQUEID = '" & Me.lblBO_uniqueID.Text & "' "
        dtBO_UNIQUE = clsDatabase.QueryDataTable(lvsSQL)

        If (dtBO_UNIQUE.Rows.Count <> 0) Then
            If Not IsDBNull(dtBO_UNIQUE.Rows(0)("ACCOUNTNO")) Then lvsACCOUNTNO = dtBO_UNIQUE.Rows(0)("ACCOUNTNO")

            Dim lvsAleart As String = "ระบบไม่อนูญาติให้ลบผู้รับผลประโยชน์นี้ ! มีการผูกผู้รับผลประโยชน์กับบัญชี  " _
                                   & lvsACCOUNTNO & " แล้ว"

            ScriptManager.RegisterStartupScript(Page, Page.GetType(),
                         "alertMessage",
                         "window.alert('" & lvsAleart & "');", True)

            grdBo.SelectedIndex = -1 : Me.lblBO_uniqueID.Text = ""

            Exit Function

        End If
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        Validate_Acct_BO_Delete = True
    End Function

    Function Validate_Acct_BO() As Boolean

        clsCheckID = New clsCheckID

        Validate_Acct_BO = False


        If Me.txtBO_uniqueID.Text = "" And Me.txtBO_PASSPORT_NO.Text = "" Then
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('กรุณาป้อนเลขที่บัตรประชาขนหรือเลขที่หนังสือเดินทางให้ถูกต้อง');", True)
            txtBO_uniqueID.Focus()
            Exit Function
        ElseIf Me.txtBO_uniqueID.Text <> "" Then
            If Not (clsCheckID.chkIDcard(txtBO_uniqueID.Text.Trim)) Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('เลขที่บัตรประชาชนไม่ถูกต้อง');", True)
                Exit Function
                txtBO_uniqueID.Focus()
            End If
        ElseIf Me.txtBO_uniqueID.Text <> "" And Me.txtBO_PASSPORT_NO.Text <> "" Then
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('เลขที่บัตรประชาชนไม่ถูกต้อง');", True)
            Exit Function
            txtBO_uniqueID.Focus()
        End If

        ''''''''''''validate ข้อมูลซ้ำ''''''''''''
        Dim mBoIdCard As String = ""
        For Each rowNumber As GridViewRow In grdBo.Rows

            mBoIdCard = rowNumber.Cells(2).Text

            If mBoIdCard.Trim = Me.txtBO_uniqueID.Text.Trim Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ข้อมูลซ้ำ ! กรูณาป้อนเลขที่บัตรประชาชนใหม่');", True)
                txtBO_uniqueID.Focus()
                Exit Function
            End If

        Next
        ''''''''''''''''''''''''''''''''''''''

        If Me.txtBO_uniqueID.Text.Trim = Me.txtUniqueID.Text.Trim Then
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ข้อมูลซ้ำกับเจ้าของบัญชี ! กรูณาป้อนเลขที่บัตรประชาชนใหม่');", True)
        End If

        If clsValid.CheckNull(Me.txtBO_FIRSTNAME_TH) = False Then Exit Function
        If clsValid.CheckNull(Me.txtBO_LASTNAME_TH) = False Then Exit Function
        If lblFILTER_RESULT_BO.Text = "" Then
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ต้องทำการตรวจกรองรายชือก่อน');", True)
            Exit Function
            lblFILTER_RESULT_BO.Focus()
        End If


        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        '''''หาว่าข้อมูลที่ป้อนมีชื่อไม่ตรงกับใน Mcustomer '''''''''''''''''''''''
        Dim dtSmartCard As DataTable = New DataTable

        Dim lvsSmartCard_FirstName As String = ""
        Dim lvsSmartCard_LastName As String = ""

        lvsSQL = ""
        lvsSQL += "      SELECT THFIRSTNAME,                                "
        lvsSQL += "             THMIDNAME,                                  "
        lvsSQL += "             THLASTNAME                                  "
        lvsSQL += "        FROM MCUSTOMER                                   "
        lvsSQL += "       WHERE UNIQUEID = '" & Me.txtBO_uniqueID.Text & "' "
        dtSmartCard = clsDatabase.QueryDataTable(lvsSQL)

        If (dtSmartCard.Rows.Count <> 0) Then

            If Not IsDBNull(dtSmartCard.Rows(0)("THFIRSTNAME")) Then lvsSmartCard_FirstName = dtSmartCard.Rows(0)("THFIRSTNAME")
            If Not IsDBNull(dtSmartCard.Rows(0)("THLASTNAME")) Then lvsSmartCard_LastName = dtSmartCard.Rows(0)("THLASTNAME")

            If lvsSmartCard_FirstName.Trim & lvsSmartCard_LastName.Trim _
                <> Me.txtBO_FIRSTNAME_TH.Text.Trim & Me.txtBO_LASTNAME_TH.Text.Trim Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(),
                              "alertMessage",
                              "window.alert('เลขที่บัตรประชาชนที่ป้อนมี-ชื่อหรือนามสกุล-ไม่ตรงกับข้อมูลจากระบบ KYC');", True)
                Exit Function
                Me.txtBO_FIRSTNAME_TH.Focus()
            End If

        End If
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

        Validate_Acct_BO = True
    End Function

    Function Validate_ID_CARD(ByVal Unique_no As Object) As Boolean

        clsCheckID = New clsCheckID

        Validate_ID_CARD = False

        If clsValid.CheckNull(Unique_no) = False Then Exit Function

        If Len(Unique_no.Text) <> 13 Then
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('เลขที่บัตรประชาชนไม่ครบ 13 หลัก');", True)
            Exit Function
            Unique_no.Focus()
        End If

        '  If clsValid.CheckNumeric_Smartcard(Unique_no) = False Then Exit Function


        If Not (clsCheckID.chkIDcard(Unique_no.text)) Then
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('เลขที่บัตรประชาชนไม่ถูกต้อง');", True)
            Exit Function
            Unique_no.Focus()
        End If


        Validate_ID_CARD = True
    End Function

    Function Validate_Acct_BO_Filter() As Boolean

        clsCheckID = New clsCheckID

        Validate_Acct_BO_Filter = False


        If Me.txtBO_uniqueID.Text = "" And Me.txtBO_PASSPORT_NO.Text = "" Then
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('กรุณาป้อนเลขที่บัตรประชาขนหรือเลขที่หนังสือเดินทางให้ถูกต้อง');", True)
            txtBO_uniqueID.Focus()
            Exit Function
        ElseIf Me.txtBO_uniqueID.Text <> "" Then
            If Not (clsCheckID.chkIDcard(txtBO_uniqueID.Text.Trim)) Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('เลขที่บัตรประชาชนไม่ถูกต้อง');", True)
                Exit Function
                txtBO_uniqueID.Focus()
            End If
        ElseIf Me.txtBO_uniqueID.Text <> "" And Me.txtBO_PASSPORT_NO.Text <> "" Then
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('เลขที่บัตรประชาชนไม่ถูกต้อง');", True)
            Exit Function
            txtBO_uniqueID.Focus()
        End If

        ''''''''''''validate ข้อมูลซ้ำ''''''''''''
        Dim mBoIdCard As String = ""
        For Each rowNumber As GridViewRow In grdBo.Rows

            mBoIdCard = rowNumber.Cells(2).Text

            If mBoIdCard.Trim = Me.txtBO_uniqueID.Text.Trim Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ข้อมูลซ้ำ ! กรูณาป้อนเลขที่บัตรประชาชนใหม่');", True)
                txtBO_uniqueID.Focus()
                Exit Function
            End If

        Next
        ''''''''''''''''''''''''''''''''''''''

        If clsValid.CheckNull(Me.txtBO_FIRSTNAME_TH) = False Then Exit Function
        If clsValid.CheckNull(Me.txtBO_LASTNAME_TH) = False Then Exit Function

        Validate_Acct_BO_Filter = True
    End Function

    Function Validate_CustName() As Boolean

        clsCheckID = New clsCheckID
        Validate_CustName = False
        If Me.txtUniqueID.Text = "" And Me.txtBO_PASSPORT_NO.Text = "" Then
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('กรุณาป้อนเลขที่บัตรประชาขนหรือเลขที่หนังสือเดินทางให้ถูกต้อง');", True)
            txtUniqueID.Focus()
            Exit Function
        ElseIf Me.txtUniqueID.Text <> "" Then
            If Not (clsCheckID.chkIDcard(txtUniqueID.Text.Trim)) Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('เลขที่บัตรประชาชนไม่ถูกต้อง');", True)
                Exit Function
                txtUniqueID.Focus()
            End If
        ElseIf Me.txtUniqueID.Text <> "" And Me.txtBO_PASSPORT_NO.Text <> "" Then
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('เลขที่บัตรประชาชนไม่ถูกต้อง');", True)
            Exit Function
            txtUniqueID.Focus()
        End If

        If clsValid.CheckNull(Me.txtNameTh1) = False Then Exit Function
        If clsValid.CheckNull(Me.txtNameTh3) = False Then Exit Function

        If clsValid.CheckNull(Me.txtNameEn1) = False Then Exit Function
        If clsValid.CheckNull(Me.txtNameEn1) = False Then Exit Function

        Validate_CustName = True
    End Function

    Protected Sub btnLOV_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLOV.Click

    End Sub

    Protected Sub chkExpire_None_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkExpire_None.CheckedChanged
        If Me.chkExpire_None.Checked = True Then
            lblFLAG_ID_CARD_WL.Text = "Y"
            Me.txtID_CARD_EXP_DD.Text = ""
            Me.txtID_CARD_EXP_MM.Text = ""
            Me.txtID_CARD_EXP_YYYY.Text = ""
            Me.txtID_CARD_EXP_DATE_TH.Text = ""
            Me.txtID_CARD_EXP_DATE_EN.Text = ""
            Me.txtID_CARD_EXP_DATE_EN_CHK.Text = ""
        Else
            lblFLAG_ID_CARD_WL.Text = "N"
        End If
    End Sub

    Protected Sub chk_ACT_SANCTION_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim dRow As DataRow

        dtSanc = New DataTable()

        dtSanc.Columns.Add(New DataColumn("SANID"))
        dtSanc.Columns.Add(New DataColumn("PASSPORT"))
        dtSanc.Columns.Add(New DataColumn("NAME_TH"))
        dtSanc.Columns.Add(New DataColumn("NAME_EN"))
        dtSanc.Columns.Add(New DataColumn("DATA_FROM"))
        dtSanc.Columns.Add(New DataColumn("UPDATE_DATE"))
        dtSanc.Columns.Add(New DataColumn("ACTIVE"))

        For Each rowSanc As GridViewRow In grdSanc.Rows
            dRow = dtSanc.NewRow()
            dRow("SANID") = rowSanc.Cells(0).Text
            dRow("PASSPORT") = rowSanc.Cells(2).Text
            dRow("NAME_TH") = rowSanc.Cells(3).Text
            dRow("NAME_EN") = rowSanc.Cells(4).Text
            dRow("DATA_FROM") = rowSanc.Cells(5).Text
            dRow("UPDATE_DATE") = rowSanc.Cells(6).Text
            dRow("ACTIVE") = CType(rowSanc.Cells(7).FindControl("chk_ACT_SANCTION"), CheckBox).Checked
            dtSanc.Rows.Add(dRow)
            dtSanc.AcceptChanges()
        Next

        Me.grdSanc.DataSource = dtSanc
        grdSanc.DataBind()
        Session("PopSanc") = dtSanc
    End Sub

    Protected Sub btnFilter_BO_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFilter_BO.Click
        Try
            Session("chkKYC") = Nothing
            Dim lvsWhatIsThis As DataSet = Session("ds")
            If Not lvsWhatIsThis Is Nothing AndAlso lvsWhatIsThis.Tables("Result").Rows.Count > 0 Then
                lblRISK_LEVEL_BO.Text = Me.hdfLevel.Value
                '''''''''''''''''''''''''''''''''''''''''''
                grdList.DataSource = lvsWhatIsThis.Tables("Result")
                grdList.DataBind()
                '''''''''''''''''''''''''''''''''''''''''''
            Else
                lblRISK_LEVEL_BO.Text = 0
            End If

            If Session("Sanction") = Nothing Then
                Me.lblFILTER_RESULT_BO.Text = "ไม่มีรายชื่อใน List"
                lblRISK_LEVEL_BO.Text = 1
            Else
                Me.lblFILTER_RESULT_BO.Text = "มีรายชื่อใน List"
            End If

            Session("Sanction") = Nothing

        Catch ex As Exception
            Console.WriteLine("")

        End Try
    End Sub

    Protected Sub btnFilter_Family_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFilter_Family.Click
        Try
            Session("chkKYC") = Nothing
            Dim lvsWhatIsThis As DataSet = Session("ds")
            If Not lvsWhatIsThis Is Nothing AndAlso lvsWhatIsThis.Tables("Result").Rows.Count > 0 Then
                lblFAM_RISK_LEVEL.Text = Me.hdfLevel.Value
                '''''''''''''''''''''''''''''''''''''''''''
                grdList.DataSource = lvsWhatIsThis.Tables("Result")
                grdList.DataBind()
                '''''''''''''''''''''''''''''''''''''''''''
            Else
                lblFAM_RISK_LEVEL.Text = 0
            End If

            If Session("Sanction") = Nothing Then
                Me.lblFAM_FILTER_RESULT.Text = "ไม่มีรายชื่อใน List"
                lblFAM_RISK_LEVEL.Text = 1
            Else
                Me.lblFAM_FILTER_RESULT.Text = "มีรายชื่อใน List"
            End If

            Session("Sanction") = Nothing

        Catch ex As Exception
            Console.WriteLine("")

        End Try
    End Sub

    Protected Sub grdNaiton_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdNaiton.SelectedIndexChanged
        If (grdNaiton.SelectedIndex = intBeforeSelectIndex_grdNaiton) Then
            grdNaiton.SelectedIndex = -1
        End If
    End Sub

    Protected Sub grdNaiton_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles grdNaiton.SelectedIndexChanging
        intBeforeSelectIndex_grdNaiton = grdNaiton.SelectedIndex
    End Sub

    Protected Sub grdOtherID_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdOtherID.SelectedIndexChanged
        If grdOtherID.SelectedIndex = intBeforeSelectIndex_OTHER Then
            grdOtherID.SelectedIndex = -1
        End If
    End Sub

    Protected Sub grdOtherID_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles grdOtherID.SelectedIndexChanging
        intBeforeSelectIndex_OTHER = grdOtherID.SelectedIndex
    End Sub

    Protected Sub grdPassport_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdPassport.SelectedIndexChanged
        If grdPassport.SelectedIndex = intBeforeSelectIndex_Passport Then
            grdPassport.SelectedIndex = -1
        End If
    End Sub

    Protected Sub grdPassport_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles grdPassport.SelectedIndexChanging
        Me.intBeforeSelectIndex_Passport = grdPassport.SelectedIndex
    End Sub

    Protected Sub grdPolitical_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdPolitical.SelectedIndexChanged
        If grdPolitical.SelectedIndex = intBeforeSelectIndex_Politician Then
            grdPolitical.SelectedIndex = -1
        End If
    End Sub

    Protected Sub grdPolitical_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles grdPolitical.SelectedIndexChanging
        Me.intBeforeSelectIndex_Politician = grdPolitical.SelectedIndex
    End Sub

    Protected Sub grdOcc_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdOcc.SelectedIndexChanged
        If grdOcc.SelectedIndex = intBeforeSelectIndex_Occ Then
            grdOcc.SelectedIndex = -1
        End If
    End Sub

    Protected Sub grdOcc_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles grdOcc.SelectedIndexChanging
        Me.intBeforeSelectIndex_Occ = grdOcc.SelectedIndex
    End Sub

    Protected Sub grdIncome_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdIncome.SelectedIndexChanged
        If grdIncome.SelectedIndex = intBeforeSelectIndex_Income Then
            grdIncome.SelectedIndex = -1
        End If
    End Sub

    Protected Sub grdIncome_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles grdIncome.SelectedIndexChanging
        Me.intBeforeSelectIndex_Income = grdIncome.SelectedIndex
    End Sub

    Protected Sub grdBo_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdBo.SelectedIndexChanged
        If grdBo.SelectedIndex = intBeforeSelectIndex_BO Then
            grdBo.SelectedIndex = -1
            Me.lblBO_uniqueID.Text = ""
        Else
            Me.lblBO_uniqueID.Text = grdBo.Rows(grdBo.SelectedIndex).Cells(2).Text
        End If
    End Sub

    Protected Sub grdBo_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles grdBo.SelectedIndexChanging
        Me.intBeforeSelectIndex_BO = grdBo.SelectedIndex
    End Sub

    Protected Sub grdFamily_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdFamily.SelectedIndexChanged
        If grdFamily.SelectedIndex = intBeforeSelectIndex_Family Then
            grdFamily.SelectedIndex = -1
        End If
    End Sub

    Protected Sub grdFamily_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles grdFamily.SelectedIndexChanging
        Me.intBeforeSelectIndex_Family = grdFamily.SelectedIndex
    End Sub

    Protected Sub grdReason_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdReason.SelectedIndexChanged
        If grdReason.SelectedIndex = intBeforeSelectIndex_Reason Then
            grdReason.SelectedIndex = -1
        End If
    End Sub

    Protected Sub grdReason_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles grdReason.SelectedIndexChanging
        Me.intBeforeSelectIndex_Reason = grdReason.SelectedIndex
    End Sub

    Protected Sub optPOL_CONNECT_N_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles optPOL_CONNECT_N.CheckedChanged
        Me.lblF_POLITIC.Text = "N"
        Me.btAddPolitical.Enabled = False
        Me.btDelPolitical.Enabled = False

        'Me.txtPOLITIC_POST_SELF.Enabled = False : Me.txtPOLITIC_POST_SELF.Text = ""
        'Me.txtPOLITIC_RELATION.Enabled = False : Me.txtPOLITIC_RELATION.Text = ""
        'Me.txtPOLITIC_POST_CONC.Enabled = False : Me.txtPOLITIC_POST_CONC.Text = ""
        'Me.txtTHFIRSTNAME.Enabled = False : Me.txtTHFIRSTNAME.Text = ""
        'Me.txtTHMIDNAME.Enabled = False : Me.txtTHMIDNAME.Text = ""
        'Me.txtTHLASTNAME.Enabled = False : Me.txtTHLASTNAME.Text = ""

        'Me.txtPOLITIC_POST_SELF.BackColor = Drawing.Color.Silver
        'Me.txtPOLITIC_RELATION.BackColor = Drawing.Color.Silver
        'Me.txtPOLITIC_POST_CONC.BackColor = Drawing.Color.Silver
        'Me.txtTHFIRSTNAME.BackColor = Drawing.Color.Silver
        'Me.txtTHMIDNAME.BackColor = Drawing.Color.Silver
        'Me.txtTHLASTNAME.BackColor = Drawing.Color.Silver

    End Sub

    Protected Sub optPOL_CONNECT_Y_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles optPOL_CONNECT_Y.CheckedChanged
        Me.lblF_POLITIC.Text = "Y"
        Me.btAddPolitical.Enabled = True
        Me.btDelPolitical.Enabled = True

        Me.txtPOLITIC_POST_SELF.Enabled = True
        Me.txtPOLITIC_RELATION.Enabled = True
        Me.txtPOLITIC_POST_CONC.Enabled = True
        Me.txtTHFIRSTNAME.Enabled = True
        Me.txtTHMIDNAME.Enabled = True
        Me.txtTHLASTNAME.Enabled = True

        Me.txtPOLITIC_POST_SELF.BackColor = Drawing.Color.White
        Me.txtPOLITIC_RELATION.BackColor = Drawing.Color.White
        Me.txtPOLITIC_POST_CONC.BackColor = Drawing.Color.White
        Me.txtTHFIRSTNAME.BackColor = Drawing.Color.White
        Me.txtTHMIDNAME.BackColor = Drawing.Color.White
        Me.txtTHLASTNAME.BackColor = Drawing.Color.White
    End Sub

    Protected Sub btnFilter_PASSPORT_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFilter_PASSPORT.Click
        Try
            Session("chkKYC") = Nothing
            Dim lvsWhatIsThis As DataSet = Session("ds")
            If Not lvsWhatIsThis Is Nothing AndAlso lvsWhatIsThis.Tables("Result").Rows.Count > 0 Then
                lblRISK_LEVEL_PASSPORT.Text = Me.hdfLevel.Value
                '''''''''''''''''''''''''''''''''''''''''''
                grdList.DataSource = lvsWhatIsThis.Tables("Result")
                grdList.DataBind()
                '''''''''''''''''''''''''''''''''''''''''''
            Else
                lblRISK_LEVEL_PASSPORT.Text = 0
            End If

            If Session("Sanction") = Nothing Then
                Me.lblFILTER_RESULT_PASSPORT.Text = "ไม่มีรายชื่อใน List"
                lblRISK_LEVEL_PASSPORT.Text = 1
            Else
                Me.lblFILTER_RESULT_PASSPORT.Text = "มีรายชื่อใน List"
            End If

            Session("Sanction") = Nothing

        Catch ex As Exception
            Console.WriteLine("")

        End Try
    End Sub

#Region "Validate data"


    Function Validate_Passport() As Boolean


        Dim mPassport_no As String = ""
        Validate_Passport = False

        If CInt(Me.lblCount_Passport.Text) = 5 Then
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ระบบอนุญาติให้ป้อนข้อมูลหนังสือเดินทางได้ไม่เกิน 5 เล่ม');", True)
            txtPASSPORT_NO.Focus()
            Exit Function
        End If

        If clsValid.CheckNull(Me.txtPASSPORT_NO) = False Then Exit Function

        For Each rowPassport As GridViewRow In grdPassport.Rows

            mPassport_no = rowPassport.Cells(1).Text

            If mPassport_no.Trim = Me.txtPASSPORT_NO.Text.Trim Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ข้อมูลซ้ำ ! กรูณาป้อนเลขที่หนังสือเดินทางใหม่');", True)
                txtPASSPORT_NO.Focus()
                Exit Function
            End If

        Next

        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        If clsValid.CheckNull(Me.txtPASSPORT_ISSUE_DD) = False Then Exit Function
        If clsValid.CheckNull(Me.txtPASSPORT_ISSUE_MM) = False Then Exit Function
        If clsValid.CheckNull(Me.txtPASSPORT_ISSUE_YYYY) = False Then Exit Function

        If (clsValid.CheckNumdayInMonth(txtPASSPORT_ISSUE_DD) = False) Then Exit Function
        If (clsValid.CheckMonthOfYear(Me.txtPASSPORT_ISSUE_MM) = False) Then Exit Function
        If (clsValid.CheckYear_TH(Me.txtPASSPORT_ISSUE_YYYY) = False) Then Exit Function
        Me.txtPASSPORT_ISSUE_DATE_TH.Text = clsValid.ConcatDate(Me.txtPASSPORT_ISSUE_DD.Text,
                                                                Me.txtPASSPORT_ISSUE_MM.Text,
                                                                Me.txtPASSPORT_ISSUE_YYYY.Text)

        Me.txtPASSPORT_ISSUE_DATE_EN.Text = clsValid.ConcatDate(Me.txtPASSPORT_ISSUE_DD.Text,
                                                               Me.txtPASSPORT_ISSUE_MM.Text,
                                                               CInt(Me.txtPASSPORT_ISSUE_YYYY.Text) - 543)

        Me.txtPASSPORT_ISSUE_DATE_EN_Chk.Text = clsValid.ConcatDate(Me.txtPASSPORT_ISSUE_DD.Text,
                                                          Me.txtPASSPORT_ISSUE_MM.Text,
                                                          CInt(Me.txtPASSPORT_ISSUE_YYYY.Text) - 544)


        If (clsValid.CheckDate(txtPASSPORT_ISSUE_DATE_EN_Chk) = False) Then
            Me.txtPASSPORT_ISSUE_DD.Focus() : Exit Function
        End If

        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        If clsValid.CheckNull(Me.txtPASSPORT_EXP_DD) = False Then Exit Function
        If clsValid.CheckNull(Me.txtPASSPORT_EXP_MM) = False Then Exit Function
        If clsValid.CheckNull(Me.txtPASSPORT_EXP_YYYY) = False Then Exit Function

        If (clsValid.CheckNumdayInMonth(txtPASSPORT_EXP_DD) = False) Then Exit Function
        If (clsValid.CheckMonthOfYear(Me.txtPASSPORT_EXP_MM) = False) Then Exit Function
        If (clsValid.CheckYear_TH(Me.txtPASSPORT_EXP_YYYY) = False) Then Exit Function

        Me.txtPASSPORT_EXP_DATE_TH.Text = clsValid.ConcatDate(Me.txtPASSPORT_EXP_DD.Text,
                                                              Me.txtPASSPORT_EXP_MM.Text,
                                                              Me.txtPASSPORT_EXP_YYYY.Text)

        Me.txtPASSPORT_EXP_DATE_EN.Text = clsValid.ConcatDate(Me.txtPASSPORT_EXP_DD.Text,
                                                              Me.txtPASSPORT_EXP_MM.Text,
                                                              CInt(Me.txtPASSPORT_EXP_YYYY.Text) - 543)

        Me.txtPASSPORT_EXP_DATE_EN_CHK.Text = clsValid.ConcatDate(Me.txtPASSPORT_EXP_DD.Text,
                                                      Me.txtPASSPORT_EXP_MM.Text,
                                                      CInt(Me.txtPASSPORT_EXP_YYYY.Text) - 544)

        If (clsValid.CheckDate(txtPASSPORT_EXP_DATE_EN_CHK) = False) Then
            Me.txtPASSPORT_EXP_DD.Focus() : Exit Function
        End If

        If DateDiff(DateInterval.Day, CDate(Me.txtPASSPORT_EXP_DATE_EN_CHK.Text), CDate(Me.txtPASSPORT_ISSUE_DATE_EN_Chk.Text)) > 0 Then
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ข้อมูลไม่ถูกต้อง ! วันที่ย้อนหลัง');", True)
            Me.txtPASSPORT_EXP_DD.Focus()
            Exit Function
        End If

        If Me.lblFILTER_RESULT_PASSPORT.Text = "" Then
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ต้องทำการตรวจกรองรายชือก่อน');", True)
            Exit Function
            Me.txtPASSPORT_NO.Focus()
        End If

        Validate_Passport = True
    End Function

    Function Validate_Other_DOC() As Boolean
        Validate_Other_DOC = False

        ''''''''Validate ข้อมูลซ้ำ''''''''''''''''''
        Dim mDocTypeAndDoc_no As String = ""
        Dim mDocType_Grid As String = ""
        Dim mDoc_No_Grid As String = ""
        Dim mDocTypeAndDoc_no_Grid As String = ""

        If DdOtherID.SelectedItem.Text = "" Then
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('กรูณาเลือกเอกสารประเภทอื่นที่้ต้องการ');", True)
            DdOtherID.Focus()
            Exit Function
        End If

        If clsValid.CheckNull(Me.txtOTH_DOC_CARDID) = False Then Exit Function

        mDocTypeAndDoc_no = DdOtherID.SelectedItem.Text.Trim & Me.txtOTH_DOC_CARDID.Text.Trim

        For Each rowFromGrid As GridViewRow In Me.grdOtherID.Rows

            mDocType_Grid = rowFromGrid.Cells(1).Text.Trim
            mDoc_No_Grid = rowFromGrid.Cells(3).Text.Trim
            mDocTypeAndDoc_no_Grid = mDocType_Grid & mDoc_No_Grid

            If mDocTypeAndDoc_no.Trim = mDocTypeAndDoc_no_Grid Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ข้อมูลซ้ำ ! กรูณาเลือกเอกสารประเภทอื่น');", True)
                DdOtherID.Focus()
                Exit Function
            End If

        Next
        '''''''''''''''''''''''''''''



        Validate_Other_DOC = True
    End Function

    Function Validate_Nation() As Boolean


        Validate_Nation = False

        ''''''''Validate ข้อมูลซ้ำ''''''''''''''''''
        Dim mNationName As String = ""
        For Each rowID As GridViewRow In grdNaiton.Rows

            mNationName = rowID.Cells(1).Text

            If mNationName = ddlNationality.SelectedItem.Text Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ข้อมูลซ้ำ ! กรูณาเลือกสัญชาติอื่น');", True)
                ddlNationality.Focus()
                Exit Function
            End If

        Next
        '''''''''''''''''''''''''''''
        Validate_Nation = True
    End Function


    Function Validate_For_All() As Boolean

        Validate_For_All = False

        ''''''''''''''''''''''''''''''''
        Panel1.Enabled = True

        btnEditCompile.Enabled = False

        Me.grdNaiton.Enabled = False
        Me.ddlNationality.Enabled = False
        Me.btAddNation.Enabled = False
        Me.btDelNation.Enabled = False

        Me.grdOcc.Enabled = False
        Me.ddlOccupation1.Enabled = False
        Me.ddlOccupation4.Enabled = False
        Me.btAddOcc.Enabled = False
        Me.btDelOcc.Enabled = False

        Me.ddlIncomeSource1.Enabled = False
        Me.btAddIncome.Enabled = False
        Me.btDelIncome.Enabled = False



        '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        If clsValid.CheckNull(Me.txtID_CARD_ISSUE_DD) = False Then Exit Function
        If clsValid.CheckNull(Me.txtID_CARD_ISSUE_MM) = False Then Exit Function
        If clsValid.CheckNull(Me.txtID_CARD_ISSUE_YYYY) = False Then Exit Function

        If (clsValid.CheckNumdayInMonth(txtID_CARD_ISSUE_DD) = False) Then Exit Function
        If (clsValid.CheckMonthOfYear(Me.txtID_CARD_ISSUE_MM) = False) Then Exit Function
        If (clsValid.CheckYear_TH(Me.txtID_CARD_ISSUE_YYYY) = False) Then Exit Function
        Me.txtID_CARD_ISSUE_DATE_TH.Text = clsValid.ConcatDate(Me.txtID_CARD_ISSUE_DD.Text,
                                                                Me.txtID_CARD_ISSUE_MM.Text,
                                                                Me.txtID_CARD_ISSUE_YYYY.Text)

        Me.txtID_CARD_ISSUE_DATE_EN.Text = clsValid.ConcatDate(Me.txtID_CARD_ISSUE_DD.Text,
                                                               Me.txtID_CARD_ISSUE_MM.Text,
                                                               CInt(Me.txtID_CARD_ISSUE_YYYY.Text) - 543)

        Me.txtID_CARD_ISSUE_DATE_EN_CHK.Text = clsValid.ConcatDate(Me.txtID_CARD_ISSUE_DD.Text,
                                                          Me.txtID_CARD_ISSUE_MM.Text,
                                                          CInt(Me.txtID_CARD_ISSUE_YYYY.Text) - 544)

        If (clsValid.CheckDate(txtID_CARD_ISSUE_DATE_EN_CHK) = False) Then
            Me.txtID_CARD_ISSUE_DD.Focus() : Exit Function
        End If

        ' '''''''''''''''
        If Me.chkExpire_None.Checked = False Then

            If clsValid.CheckNull(Me.txtID_CARD_EXP_DD) = False Then Exit Function
            If clsValid.CheckNull(Me.txtID_CARD_EXP_MM) = False Then Exit Function
            If clsValid.CheckNull(Me.txtID_CARD_EXP_YYYY) = False Then Exit Function

            If (clsValid.CheckNumdayInMonth(txtID_CARD_EXP_DD) = False) Then Exit Function
            If (clsValid.CheckMonthOfYear(Me.txtID_CARD_EXP_MM) = False) Then Exit Function
            If (clsValid.CheckYear_TH(Me.txtID_CARD_EXP_YYYY) = False) Then Exit Function
            Me.txtID_CARD_EXP_DATE_TH.Text = clsValid.ConcatDate(Me.txtID_CARD_EXP_DD.Text,
                                                                 Me.txtID_CARD_EXP_MM.Text,
                                                                 Me.txtID_CARD_EXP_YYYY.Text)

            Me.txtID_CARD_EXP_DATE_EN.Text = clsValid.ConcatDate(Me.txtID_CARD_EXP_DD.Text,
                                                                   Me.txtID_CARD_EXP_MM.Text,
                                                                   CInt(Me.txtID_CARD_EXP_YYYY.Text) - 543)

            Me.txtID_CARD_EXP_DATE_EN_CHK.Text = clsValid.ConcatDate(Me.txtID_CARD_EXP_DD.Text,
                                                              Me.txtID_CARD_EXP_MM.Text,
                                                              CInt(Me.txtID_CARD_EXP_YYYY.Text) - 544)

            If (clsValid.CheckDate(txtID_CARD_EXP_DATE_EN_CHK) = False) Then
                Me.txtID_CARD_EXP_DD.Focus() : Exit Function
            End If

            If DateDiff(DateInterval.Day, CDate(Me.txtID_CARD_EXP_DATE_EN_CHK.Text), CDate(Me.txtID_CARD_ISSUE_DATE_EN_CHK.Text)) > 0 Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ข้อมูลไม่ถูกต้อง ! ช่วงวันที่สลับกัน');", True)
                Me.txtID_CARD_EXP_DD.Focus()
                Exit Function
            End If

        End If

        ' ''''''''''
        If CInt(Me.lblCount_Nation.Text) = 0 Then
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('กรุณาป้อนข้อมูลสัญชาติให้ครบถ้วน');", True)
            Me.ddlNationality.Focus()
            Exit Function
        End If

        ''''''''''Birth Date '''''''''''''''''''''''''''''''''''''''''''''''''''
        If clsValid.CheckNull(Me.txtBIRTH_DATE_TH_DD) = False Then Exit Function
        If clsValid.CheckNull(Me.txtBIRTH_DATE_TH_MM) = False Then Exit Function
        If clsValid.CheckNull(Me.txtBIRTH_DATE_TH_YYYY) = False Then Exit Function

        If (clsValid.CheckNumdayInMonth(txtBIRTH_DATE_TH_DD) = False) Then Exit Function
        If (clsValid.CheckMonthOfYear(Me.txtBIRTH_DATE_TH_MM) = False) Then Exit Function
        If (clsValid.CheckYear_TH(Me.txtBIRTH_DATE_TH_YYYY) = False) Then Exit Function
        Me.lbBIRTH_DATE_TH.Text = clsValid.ConcatDate(Me.txtBIRTH_DATE_TH_DD.Text,
                                                      Me.txtBIRTH_DATE_TH_MM.Text,
                                                      Me.txtBIRTH_DATE_TH_YYYY.Text)



        Me.lbBIRTH_DATE_Check.Text = clsValid.ConcatDate(Me.txtBIRTH_DATE_TH_DD.Text,
                                                         Me.txtBIRTH_DATE_TH_MM.Text,
                                                         CInt(Me.txtBIRTH_DATE_TH_YYYY.Text) - 544)

        If (clsValid.CheckDate(lbBIRTH_DATE_Check) = False) Then
            Me.txtBIRTH_DATE_TH_DD.Focus() : Exit Function
        End If

        Me.txtBIRTH_DATE_EN_DD.Text = Me.txtBIRTH_DATE_TH_DD.Text
        Me.txtBIRTH_DATE_EN_MM.Text = Me.txtBIRTH_DATE_TH_MM.Text
        Me.txtBIRTH_DATE_EN_YYYY.Text = CInt(Me.txtBIRTH_DATE_TH_YYYY.Text) - 543

        Me.lbBIRTH_DATE_EN.Text = (clsValid.ConcatDate(Me.txtBIRTH_DATE_EN_DD.Text,
                                                       Me.txtBIRTH_DATE_EN_MM.Text,
                                                       CInt(Me.txtBIRTH_DATE_EN_YYYY.Text)))
        '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

        If Me.ddlGender.SelectedIndex <= 0 Then
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('กรุณาป้อนข้อมูลเพศให้ครบถ้วน');", True)
            Me.ddlGender.Focus()
            Exit Function
        End If

        If Me.ddlMaritalStatus.SelectedIndex <= 0 Then
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('กรุณาป้อนข้อมูลสถานะการสมรสให้ครบถ้วน');", True)
            Me.ddlMaritalStatus.Focus()
            Exit Function
        End If

        If Me.optPOL_CONNECT_Y.Checked = True Then
            Me.lblF_POLITIC.Text = "Y"
        Else
            Me.lblF_POLITIC.Text = "N"
        End If

        If Me.lblF_POLITIC.Text = "Y" And CInt(Me.lblCount_Politic.Text) = 0 Then
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('กรุณาป้อนข้อมูลบุคคลที่เกี่ยวข้องกับนักการเมืองให้ครบถ้วน');", True)
            Me.optPOL_CONNECT_Y.Focus()
            Exit Function
        ElseIf Me.lblF_POLITIC.Text = "N" And CInt(Me.lblCount_Politic.Text) <> 0 Then
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ข้อมูลขัดแย้ง ! กรุณาเลือก-มีความสัมพันธ์กรณีที่เกี่ยวข้องกับการเมือง-หรือข้อมูลบุคคลที่เกี่ยวข้องกับนักการเมือง');", True)
            Me.optPOL_CONNECT_Y.Focus()
            Exit Function
        End If

        '''''''''' Occupation '''''''''''''''''
        If CInt(Me.lblCount_OCC.Text) = 0 Then
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('กรุณาป้อนข้อมูลอาชีพให้ครบถ้วน');", True)
            Me.ddlOccupation1.Focus()
            Exit Function
        End If

        '''''' Income Source '''''''''''''''''''
        If CInt(Me.lblCount_Inc_Source.Text) = 0 Then
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('กรุณาป้อนข้อมูลแหล่งเงินให้ครบถ้วน');", True)
            Me.ddlIncomeSource1.Focus()
            Exit Function
        End If



        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        Validate_For_All = True

        ''''''''''''''''''''''''''''''''''''''''
        Panel1.Enabled = False

        Me.btnEditCompile.Enabled = True

        Me.grdNaiton.Enabled = True
        Me.ddlNationality.Enabled = True
        Me.btAddNation.Enabled = True
        Me.btDelNation.Enabled = True

        Me.grdOcc.Enabled = True
        Me.ddlOccupation1.Enabled = True
        Me.ddlOccupation4.Enabled = True
        Me.btAddOcc.Enabled = True
        Me.btDelOcc.Enabled = True

        Me.ddlIncomeSource1.Enabled = True
        Me.btAddIncome.Enabled = True
        Me.btDelIncome.Enabled = True
        '''''''''''''''''''''''''''''''''''''''
    End Function

    Function Validate_beFore_FindRisk() As Boolean

        Validate_beFore_FindRisk = False



        ' ''''''''''
        If CInt(Me.lblCount_Nation.Text) = 0 Then
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('กรุณาป้อนข้อมูลสัญชาติให้ครบถ้วน');", True)
            Me.ddlNationality.Focus()
            Exit Function
        End If


        '''''''''' Occupation '''''''''''''''''
        If CInt(Me.lblCount_OCC.Text) = 0 Then
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('กรุณาป้อนข้อมูลอาชีพให้ครบถ้วน');", True)
            Me.ddlOccupation1.Focus()
            Exit Function
        End If

        '''''' Income Source '''''''''''''''''''
        If CInt(Me.lblCount_Inc_Source.Text) = 0 Then
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('กรุณาป้อนข้อมูลแหล่งเงินให้ครบถ้วน');", True)
            Me.ddlIncomeSource1.Focus()
            Exit Function
        End If



        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        Validate_beFore_FindRisk = True

    End Function

#End Region

#Region "Add data to grid"

    Protected Sub btAddPassport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btAddPassport.Click
        Me.Add_To_grid_Passport()
    End Sub

    Sub Add_To_Grid_Other_Doc()

        If Validate_Other_DOC() = False Then Exit Sub

        'check session of data table
        If Not (Session("PopOtherID") Is Nothing) Then
            Me.dtOtherID = Session("PopOtherID")
        End If

        '''''''' insert data to grid row '''''''''''''''''''''''''''''''''''''''''''''''''
        Me.dtOtherID.Rows.Add(Me.DdOtherID.SelectedItem,
                              Me.DdOtherID.SelectedValue,
                              Me.txtOTH_DOC_CARDID.Text,
                              True)

        Me.dtOtherID.AcceptChanges()
        Me.grdOtherID.DataSource = Me.dtOtherID
        Me.grdOtherID.DataBind()

        ''''จำนวนแถว ''''''''''''''''''''''''''''''''''''''
        Me.lblCount_Oth_Doc.Text = Me.dtOtherID.Rows.Count
        Me.DdOtherID.SelectedIndex = 0
        ''''''''''''''''''''''''''''''''''''''''''''''''''
        Me.txtOTH_DOC_CARDID.Text = ""
        Me.DdOtherID.Focus()
    End Sub

    Protected Sub btAddOtherID_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btAddOtherID.Click
        Me.Add_To_Grid_Other_Doc()
    End Sub

    Sub Add_To_Grid_Nation()

        If Validate_Nation() = False Then Exit Sub

        'check session of data table
        If Not (Session("PopNation") Is Nothing) Then
            dtNation = Session("PopNation")
        End If

        '''''''' insert data to grid row '''''''''''''''''''''''''''''''''''''''''''''''''

        '''''''''''''
        Dim dtRisk_Level As DataTable = New DataTable
        Dim lvsRisk As Integer = 1

        lvsSQL = ""
        lvsSQL += "     SELECT RISK                                                             "
        lvsSQL += "       FROM KYCADMIN.MNATIONALITY                                            "
        lvsSQL += "      WHERE NATIONCODE = '" & CInt(Me.ddlNationality.SelectedItem.Value) & "'"

        dtRisk_Level = clsDatabase.QueryDataTable(lvsSQL)

        If (dtRisk_Level.Rows.Count <> 0) Then
            If Not IsDBNull(dtRisk_Level.Rows(0)("RISK")) Then lvsRisk = dtRisk_Level.Rows(0)("RISK")
        End If
        ''''''''''

        dtNation.Rows.Add(ddlNationality.SelectedItem,
                          CInt(ddlNationality.SelectedItem.Value),
                          lvsRisk,
                          True)
        dtNation.AcceptChanges()
        grdNaiton.DataSource = dtNation
        grdNaiton.DataBind()
        '''''Number of Rows ''''''''''''''''''''''''''
        lblCount_Nation.Text = Me.dtNation.Rows.Count
        ''''''''''''''''''''''''''''''''''''''''''''''

        ''''deselect '''''''''''''''''''
        grdNaiton.SelectedIndex = -1
        ''''''''''''''''''''''''''''''''

        'now bind datatable to gridview... 
        Session("PopNation") = dtNation
    End Sub
    Protected Sub btAddNation_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btAddNation.Click
        Add_To_Grid_Nation()
    End Sub

    Protected Sub btAddPolitical_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btAddPolitical.Click
        Me.Add_To_grid_Politic()
    End Sub

    Sub Add_To_grid_Politic()

        If Validate_Potician_Concern() = False Then Exit Sub

        'check session of data table
        If Not (Session("PopPolitical") Is Nothing) Then
            Me.dtPolitical = Session("PopPolitical")
        End If

        '''''''' insert data to grid row '''''''''''''''''''''''''''''''''''''''''''''''''
        dtPolitical.Rows.Add(Me.ddlPrefixTH_POLITIC.SelectedValue,
                             Me.ddlPrefixTH_POLITIC.SelectedItem,
                             Me.txtTHFIRSTNAME.Text,
                             Me.txtTHMIDNAME.Text,
                             Me.txtTHLASTNAME.Text,
                             Me.ddlPrefixEN_POLITIC.SelectedValue,
                             Me.ddlPrefixEN_POLITIC.SelectedItem,
                             Me.txtenFIRSTNAME.Text,
                             Me.txtENMIDNAME.Text,
                             Me.txtENLASTNAME.Text,
                             Me.txtPOLITIC_POST_CONC.Text,
                             Me.txtPOLITIC_RELATION.Text,
                             True)
        dtPolitical.AcceptChanges()
        Me.grdPolitical.DataSource = dtPolitical
        Me.grdPolitical.DataBind()
        ''''Number of Rows '''''''''''''''''''''''''''''''''' 
        Me.lblCount_Politic.Text = Me.dtPolitical.Rows.Count
        '''''''''''''''''''''''''''''''''''''''''''''''''''''

        ''''deselect 
        Me.grdPolitical.SelectedIndex = -1

        'now bind datatable to gridview... 
        Session("PopPolitical") = Me.dtPolitical

        ''''''clear screen
        Me.txtPOLITIC_RELATION.Text = ""
        Me.txtPOLITIC_POST_CONC.Text = ""
        Me.txtTHFIRSTNAME.Text = ""
        Me.txtTHMIDNAME.Text = ""
        Me.txtTHLASTNAME.Text = ""

        Me.txtPOLITIC_RELATION.Focus()

    End Sub

    Protected Sub btAddOcc_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btAddOcc.Click
        Me.Add_To_grid_Occ()
    End Sub

    Sub Add_To_grid_Occ()

        Dim clsDropDown As New clsMasterDropDown

        If Validate_Occupation() = False Then Exit Sub

        'check session of data table
        If Not (Session("PopOcc") Is Nothing) Then
            Me.dtOcc = Session("PopOcc")
        End If

        If Me.txtOccOther1.Text = "" Then Me.txtOccOther1.Text = "-"

        '''''''''''''
        Dim dtRisk_Level As DataTable = New DataTable
        Dim lvsRisk As String = ""

        lvsSQL = ""
        lvsSQL += "     SELECT RISK                                                     "
        lvsSQL += "       FROM KYCADMIN.MOCCUPATION_SUB                                 "
        lvsSQL += "      WHERE OCCCODE = '" & Me.ddlOccupation1.SelectedValue & "'      "
        lvsSQL += "        AND OCCCODE_SUB = '" & Me.ddlOccupation4.SelectedValue & "'  "
        dtRisk_Level = clsDatabase.QueryDataTable(lvsSQL)

        If (dtRisk_Level.Rows.Count <> 0) Then
            If Not IsDBNull(dtRisk_Level.Rows(0)("RISK")) Then lvsRisk = dtRisk_Level.Rows(0)("RISK")
        End If
        ''''''''''

        '''''''' insert data to grid row '''''''''''''''''''''''''''''''''''''''''''''''''
        dtOcc.Rows.Add(Me.ddlOccupation1.SelectedItem,
                       Me.ddlOccupation1.SelectedValue,
                       Me.ddlOccupation4.SelectedItem,
                       Me.txtOccOther1.Text,
                       Me.ddlOccupation4.SelectedValue,
                       Me.txtPOSITION.Text,
                       lvsRisk,
                       True)
        dtOcc.AcceptChanges()
        Me.grdOcc.DataSource = dtOcc
        Me.grdOcc.DataBind()
        ''''Number of Rows '''''''''''''''''''''''
        Me.lblCount_OCC.Text = Me.dtOcc.Rows.Count
        '''''''''''''''''''''''''''''''''''''''''''

        ''''deselect 
        Me.grdOcc.SelectedIndex = -1

        'now bind datatable to gridview... 
        Session("PopOcc") = Me.dtOcc

        ''''Clear Screen'''''''''
        clsDropDown.setOccupationToDdl(ddlOccupation1, 1)
        ddlOccupation4.Items.Clear()
        Me.txtOccOther1.Text = ""
        Me.txtPOSITION.Text = ""
        Me.txtBizOther1.Text = ""
        Me.ddlOccupation1.Focus()

    End Sub

    Protected Sub btAddIncome_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btAddIncome.Click
        Me.Add_To_grid_Inc_Source()
    End Sub

    Sub Add_To_grid_Inc_Source()

        If Validate_Income() = False Then Exit Sub

        'check session of data table
        If Not (Session("PopINCOME") Is Nothing) Then
            Me.dtIncome = Session("PopINCOME")
        End If

        '''''''''''''


        '''''''''
        Dim dtMNAT As DataTable = New DataTable
        Dim lvsNationNameThai As String = ""
        Dim lvsRisk As Integer = 0

        lvsSQL = ""
        lvsSQL += "     SELECT COUNTYNAMETHAI, RISK                                     "
        lvsSQL += "       FROM KYCADMIN.MNATIONALITY                                    "
        lvsSQL += "      WHERE NATIONCODE = '" & Me.ddlIncomeSource1.SelectedValue & "' "
        dtMNAT = clsDatabase.QueryDataTable(lvsSQL)

        If (dtMNAT.Rows.Count <> 0) Then
            If Not IsDBNull(dtMNAT.Rows(0)("COUNTYNAMETHAI")) Then lvsNationNameThai = dtMNAT.Rows(0)("COUNTYNAMETHAI")
            If Not IsDBNull(dtMNAT.Rows(0)("RISK")) Then lvsRisk = dtMNAT.Rows(0)("RISK")
        End If
        ''''''''''

        '''''''' insert data to grid row '''''''''''''''''''''''''''''''''''''''''''''''''
        dtIncome.Rows.Add(Me.ddlIncomeSource1.SelectedItem,
                          Me.ddlIncomeSource1.SelectedValue,
                          lvsNationNameThai,
                          lvsRisk,
                          True)
        dtIncome.AcceptChanges()
        Me.grdIncome.DataSource = dtIncome
        Me.grdIncome.DataBind()
        ''''Number of Rows ''''''''''''''''''''''''''''''''''
        Me.lblCount_Inc_Source.Text = Me.dtIncome.Rows.Count
        '''''''''''''''''''''''''''''''''''''''''''''''''''''
        ''''deselect ''''''''''''''''''''' 
        Me.grdIncome.SelectedIndex = -1
        ''''''''''''''''''''''''''''''''''
        '''''now bind datatable to gridview... 
        Session("PopINCOME") = Me.dtIncome

        ''''Clear Screen'''''''''
        Me.ddlIncomeSource1.SelectedIndex = -1
        Me.ddlIncomeSource1.Focus()
    End Sub


    Protected Sub btAddBo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btAddBo.Click
        Add_To_grid_BO()
    End Sub

    Sub Add_To_grid_BO()

        If Me.Validate_Acct_BO = False Then Exit Sub

        'check session of data table
        If Not (Session("PopBo") Is Nothing) Then
            Me.dtBo = Session("PopBo")
        End If


        '''''''' insert data to grid row '''''''''''''''''''''''''''''''''''''''''''''''''
        Dim lvsddlType As Integer = 0
        Dim lvsddlDESC As String = ""
        If ddlOTH_ID_BO.SelectedIndex = -1 Then
            lvsddlType = ""
            lvsddlDESC = ""
        Else
            lvsddlType = ddlOTH_ID_BO.SelectedIndex
            lvsddlDESC = ddlOTH_ID_BO.SelectedItem.Text

        End If

        dtBo.Rows.Add(Me.txtBO_CIF_NO.Text,
                      Me.txtBO_uniqueID.Text,
                      Me.txtBO_PASSPORT_NO.Text,
                      lvsddlType,
                      lvsddlDESC,
                      Me.txtOTH_ID_NO_BO.Text,
                      Me.ddlPrefixTH_BO.SelectedIndex,
                      Me.ddlPrefixTH_BO.SelectedItem,
                      Me.txtBO_FIRSTNAME_TH.Text,
                      Me.txtBO_MIDNAME_TH.Text,
                      Me.txtBO_LASTNAME_TH.Text,
                      Me.ddlPrefixEN_BO.SelectedIndex,
                      Me.ddlPrefixEN_BO.SelectedItem,
                      Me.txtBO_FIRSTNAME_EN.Text,
                      Me.txtBO_MIDNAME_EN.Text,
                      Me.txtBO_LASTNAME_EN.Text,
                      Me.txtBO_ACC_OWN_RELATION.Text,
                      Me.lblFILTER_RESULT_BO.Text,
                      Me.lblRISK_LEVEL_BO.Text,
                      True)
        dtBo.AcceptChanges()
        Me.grdBo.DataSource = dtBo
        Me.grdBo.DataBind()
        ''''Number of Rows '''''''''''''''''''''
        Me.lblCount_BO.Text = Me.dtBo.Rows.Count
        ''''''''''''''''''''''''''''''''''''''''
        ''''deselect '''''''''''''''
        Me.grdBo.SelectedIndex = -1
        ''''''''''''''''''''''''''''
        'now bind datatable to gridview... 
        Session("PopBo") = Me.dtBo

        '''''Clear Screen '''''''''''''''
        Me.Clear_BO()
        Me.txtBO_uniqueID.Focus()

    End Sub

    Sub Clear_BO()

        Me.txtBO_CIF_NO.Text = ""
        Me.txtBO_uniqueID.Text = ""
        Me.txtBO_PASSPORT_NO.Text = ""

        Me.ddlPrefixTH_BO.SelectedIndex = -1
        Me.txtBO_FIRSTNAME_TH.Text = ""
        Me.txtBO_MIDNAME_TH.Text = ""
        Me.txtBO_LASTNAME_TH.Text = ""

        Me.ddlPrefixEN_BO.SelectedIndex = -1
        Me.txtBO_FIRSTNAME_EN.Text = ""
        Me.txtBO_MIDNAME_EN.Text = ""
        Me.txtBO_LASTNAME_EN.Text = ""

        Me.txtBO_ACC_OWN_RELATION.Text = ""

        Me.lblFILTER_RESULT_BO.Text = ""
        Me.lblRISK_LEVEL_BO.Text = ""

    End Sub

    Sub Set_Family_Enable_False()

        Me.txtFAM_CIF_NO.Text = ""
        Me.txtFAM_UNIQUEID.Text = ""
        Me.txtFAM_PASSPORT_NO.Text = ""
        Me.ddlOTH_ID_FAM.Enabled = False
        Me.txtOTH_ID_NO_FAM.Text = "" : Me.txtOTH_ID_NO_FAM.BackColor = Drawing.Color.Silver
        Me.txtOTH_ID_NO_FAM.Enabled = False
        Me.txtFAM_FIRSTNAME_TH.Text = ""
        Me.txtFAM_LASTNAME_TH.Text = ""
        Me.txtFAM_MIDNAME_TH.Text = ""
        Me.txtFAM_FIRSTNAME_EN.Text = ""
        Me.txtFAM_LASTNAME_EN.Text = ""
        Me.txtFAM_MIDNAME_EN.Text = ""

        Me.ddlPrefixTH_FAM.Enabled = False
        Me.ddlPrefixEN_FAM.Enabled = False
        Me.txtFAM_CIF_NO.Enabled = False : Me.txtFAM_CIF_NO.BackColor = Drawing.Color.Silver
        Me.txtFAM_UNIQUEID.Enabled = False : Me.txtFAM_UNIQUEID.BackColor = Drawing.Color.Silver
        Me.txtFAM_PASSPORT_NO.Enabled = False : Me.txtFAM_PASSPORT_NO.BackColor = Drawing.Color.Silver
        Me.ddlFAM_CUS_RELATION.Enabled = False
        Me.txtFAM_FIRSTNAME_TH.Enabled = False : Me.txtFAM_FIRSTNAME_TH.BackColor = Drawing.Color.Silver
        Me.txtFAM_LASTNAME_TH.Enabled = False : Me.txtFAM_LASTNAME_TH.BackColor = Drawing.Color.Silver
        Me.txtFAM_MIDNAME_TH.Enabled = False : Me.txtFAM_MIDNAME_TH.BackColor = Drawing.Color.Silver
        Me.txtFAM_FIRSTNAME_EN.Enabled = False : Me.txtFAM_FIRSTNAME_EN.BackColor = Drawing.Color.Silver
        Me.txtFAM_LASTNAME_EN.Enabled = False : Me.txtFAM_LASTNAME_EN.BackColor = Drawing.Color.Silver
        Me.txtFAM_MIDNAME_EN.Enabled = False : Me.txtFAM_MIDNAME_EN.BackColor = Drawing.Color.Silver
        Me.btnFilter_Family.Enabled = False
        Me.btAddFamily.Enabled = False
        Me.btDelFamily.Enabled = False
    End Sub

    Sub Set_Family_Enable_True()
        Me.ddlOTH_ID_FAM.Enabled = True

        Me.ddlPrefixTH_FAM.Enabled = True
        Me.ddlPrefixEN_FAM.Enabled = True
        Me.chkCustDeny_to_give_information.Enabled = True
        Me.txtFAM_CIF_NO.Enabled = True : Me.txtFAM_CIF_NO.BackColor = Drawing.Color.White
        Me.txtFAM_UNIQUEID.Enabled = True : Me.txtFAM_UNIQUEID.BackColor = Drawing.Color.White
        Me.txtFAM_PASSPORT_NO.Enabled = True : Me.txtFAM_PASSPORT_NO.BackColor = Drawing.Color.White
        Me.txtOTH_ID_NO_FAM.Enabled = True : Me.txtOTH_ID_NO_FAM.BackColor = Drawing.Color.White
        Me.ddlFAM_CUS_RELATION.Enabled = True
        Me.txtFAM_FIRSTNAME_TH.Enabled = True : Me.txtFAM_FIRSTNAME_TH.BackColor = Drawing.Color.White
        Me.txtFAM_LASTNAME_TH.Enabled = True : Me.txtFAM_LASTNAME_TH.BackColor = Drawing.Color.White
        Me.txtFAM_MIDNAME_TH.Enabled = True : Me.txtFAM_MIDNAME_TH.BackColor = Drawing.Color.White
        Me.txtFAM_FIRSTNAME_EN.Enabled = True : Me.txtFAM_FIRSTNAME_EN.BackColor = Drawing.Color.White
        Me.txtFAM_LASTNAME_EN.Enabled = True : Me.txtFAM_LASTNAME_EN.BackColor = Drawing.Color.White
        Me.txtFAM_MIDNAME_EN.Enabled = True : Me.txtFAM_MIDNAME_EN.BackColor = Drawing.Color.White
        Me.btnFilter_Family.Enabled = True
        Me.btAddFamily.Enabled = True
        Me.btDelFamily.Enabled = True
    End Sub

    Protected Sub btAddFamily_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btAddFamily.Click
        Add_To_Grid_family()
    End Sub

    Sub Add_To_Grid_family()

        If Validate_Acct_Family_Concern() = False Then Exit Sub

        'check session of data table
        If Not (Session("PopFamily") Is Nothing) Then
            Me.dtFamily = Session("PopFamily")
        End If


        '''''''' insert data to grid row '''''''''''''''''''''''''''''''''''''''''''''''''

        Dim lvsddlType As Integer = 0
        Dim lvsddlDESC As String = ""
        If ddlOTH_ID_FAM.SelectedIndex = -1 Then
            lvsddlType = ""
            lvsddlDESC = ""
        Else
            lvsddlType = ddlOTH_ID_FAM.SelectedIndex
            lvsddlDESC = ddlOTH_ID_FAM.SelectedItem.Text

        End If
        dtFamily.Rows.Add(Me.txtFAM_CIF_NO.Text,
                          Me.txtFAM_UNIQUEID.Text,
                          Me.txtFAM_PASSPORT_NO.Text,
                          lvsddlType,
                          lvsddlDESC,
                          Me.txtOTH_ID_NO_FAM.Text.Trim,
                          Me.ddlPrefixTH_FAM.SelectedIndex,
                          Me.ddlPrefixTH_FAM.SelectedItem,
                          Me.txtFAM_FIRSTNAME_TH.Text,
                          Me.txtFAM_MIDNAME_TH.Text,
                          Me.txtFAM_LASTNAME_TH.Text,
                          Me.ddlPrefixEN_FAM.SelectedIndex,
                          Me.ddlPrefixEN_FAM.SelectedItem,
                          Me.txtFAM_FIRSTNAME_EN.Text,
                          Me.txtFAM_MIDNAME_EN.Text,
                          Me.txtFAM_LASTNAME_EN.Text,
                          Me.ddlFAM_CUS_RELATION.SelectedItem,
                          Me.lblFAM_FILTER_RESULT.Text,
                          Me.lblFAM_RISK_LEVEL.Text,
                          True)

        dtFamily.AcceptChanges()
        Me.grdFamily.DataSource = dtFamily
        Me.grdFamily.DataBind()
        ''''Number of Rows '''''''''''''''''''''''''''
        Me.lblCount_Family.Text = Me.dtFamily.Rows.Count
        ''''''''''''''''''''''''''''''''''''''''''''''

        ''''deselect 
        Me.grdFamily.SelectedIndex = -1

        'now bind datatable to gridview... 
        Session("PopFamily") = Me.dtFamily

        ''''Clear Screen ''''''''''
        Me.txtFAM_CIF_NO.Text = ""
        Me.txtFAM_UNIQUEID.Text = ""
        Me.txtFAM_PASSPORT_NO.Text = ""

        Me.txtFAM_FIRSTNAME_TH.Text = ""
        Me.txtFAM_MIDNAME_TH.Text = ""
        Me.txtFAM_LASTNAME_TH.Text = ""

        Me.txtFAM_FIRSTNAME_EN.Text = ""
        Me.txtFAM_MIDNAME_EN.Text = ""
        Me.txtFAM_LASTNAME_EN.Text = ""

        Me.lblFAM_FILTER_RESULT.Text = ""
        Me.lblFAM_RISK_LEVEL.Text = ""

        Me.txtFAM_CIF_NO.Focus()

    End Sub


    Protected Sub btAddReason_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btAddReason.Click
        Add_to_grid_Reason()
    End Sub

    Sub Add_To_grid_Reason()

        If Validate_Reason() = False Then Exit Sub

        'check session of data table
        If Not (Session("PopReason") Is Nothing) Then
            Me.dtReason = Session("PopReason")
        End If
        Dim strUser As String = clsSessionMenuRight.getUserName

        '''''''' insert data to grid row '''''''''''''''''''''''''''''''''''''''''''''''''
        dtReason.Rows.Add(Me.txtReasonApp.Text,
                          Now,
                          strUser,
                          True)

        dtReason.AcceptChanges()
        Me.grdReason.DataSource = Me.dtReason
        Me.grdReason.DataBind()

        ''''Number of Rows''''''''''''''''''''''''''''''
        Me.lblCount_Reason.Text = Me.dtReason.Rows.Count
        ''''''''''''''''''''''''''''''''''''''''''''''''

        ''''deselect 
        Me.grdReason.SelectedIndex = -1

        'now bind datatable to gridview... 
        Session("PopReason") = Me.dtReason

        ''''Clear Screen ''''''''''''
        Me.txtReasonApp.Text = ""
        Me.txtReasonApp.Focus()
    End Sub

    Sub Add_To_grid_Passport()


        If Validate_Passport() = False Then Exit Sub

        'check session of data table
        If Not (Session("PopPassport") Is Nothing) Then
            Me.dtPassport = Session("PopPassport")
        End If

        '''''''' insert data to grid row '''''''''''''''''''''''''''''''''''''''''''''''''
        Me.dtPassport.Rows.Add(Me.txtPASSPORT_NO.Text,
                               Me.txtPASSPORT_ISSUE_DATE_TH.Text,
                               Me.txtPASSPORT_EXP_DATE_TH.Text,
                               Me.lblFILTER_RESULT_PASSPORT.Text,
                               Me.lblRISK_LEVEL_PASSPORT.Text,
                               True)

        Me.dtPassport.AcceptChanges()
        Me.grdPassport.DataSource = Me.dtPassport
        Me.grdPassport.DataBind()

        ''''Number of Rows'''''''''''''''''''''''''''''''
        Me.lblCount_Passport.Text = dtPassport.Rows.Count
        '''''''''''''''''''''''''''''''''''''''''''''''''

        Me.txtPASSPORT_NO.Text = ""
        Me.txtPASSPORT_ISSUE_DD.Text = "" : Me.txtPASSPORT_ISSUE_MM.Text = "" : Me.txtPASSPORT_ISSUE_YYYY.Text = ""
        Me.txtPASSPORT_EXP_DD.Text = "" : Me.txtPASSPORT_EXP_MM.Text = "" : Me.txtPASSPORT_EXP_YYYY.Text = ""
        Me.txtPASSPORT_ISSUE_DATE_TH.Text = "" : Me.txtPASSPORT_ISSUE_DATE_EN.Text = "" : Me.txtPASSPORT_ISSUE_DATE_EN_Chk.Text = ""
        Me.txtPASSPORT_EXP_DATE_TH.Text = "" : Me.txtPASSPORT_EXP_DATE_EN.Text = "" : Me.txtPASSPORT_EXP_DATE_EN_CHK.Text = ""
        Me.lblFILTER_RESULT_PASSPORT.Text = ""
        Me.lblRISK_LEVEL_PASSPORT.Text = ""
        Me.txtPASSPORT_NO.Focus()
    End Sub


#End Region

#Region "Delete data from grid"

    Protected Sub btDelPassport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btDelPassport.Click
        Me.Delete_gridRow_grdPassport()
    End Sub

    Protected Sub btDelOtherID_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btDelOtherID.Click
        Delete_gridRow_grdOther_ID()
    End Sub

    Protected Sub btDelNation_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btDelNation.Click
        Delete_gridRow_grdNation()
    End Sub

    Protected Sub btDelPolitical_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btDelPolitical.Click
        Delete_gridRow_grdPolitical()
    End Sub

    Protected Sub btDelOcc_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btDelOcc.Click
        Delete_gridRow_grdOcc()
    End Sub

    Protected Sub btDelIncome_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btDelIncome.Click
        Delete_gridRow_grdIncome()
    End Sub

    Protected Sub btDelBo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btDelBo.Click
        Delete_grdRow_grdBO()
    End Sub

    Protected Sub btDelFamily_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btDelFamily.Click
        Delete_grdRow_grdFamily()
    End Sub


    Sub Delete_gridRow_grdPassport()

        Try

            Dim index As Integer = grdPassport.SelectedIndex
            If index = -1 Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('ต้องเลือกเลขที่หนังสือเดินทางที่ต้องการลบก่อน')", True)
            Else


                ''''check session of data table
                If Not (Session("PopPassport") Is Nothing) Then
                    Me.dtPassport = Session("PopPassport")
                End If
                ''''remove row at...
                dtPassport.Rows.RemoveAt(index)
                dtPassport.AcceptChanges()

                ''''bind data again
                grdPassport.DataSource = dtPassport
                grdPassport.DataBind()

                ''''Number of Rows'''''''''''''''''''''''''''''''
                Me.lblCount_Passport.Text = dtPassport.Rows.Count
                '''''''''''''''''''''''''''''''''''''''''''''''''
                ''''deselect 
                grdPassport.SelectedIndex = -1
                Me.lblAuthor_Req_Passport.Text = "Y"
            End If

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Page, _
                                                Page.GetType(), _
                                                "clientScript", _
                                                "alert('" + ex.Message.Replace("'", "") + "')", _
                                                True)
        End Try

    End Sub

    Sub Delete_gridRow_grdOther_ID()
        Try

            Dim index As Integer = grdOtherID.SelectedIndex
            If index = -1 Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('ต้องเลือกเลขที่เอกสารที่ต้องการลบก่อน')", True)
            Else
                'check session of data table
                If Not (Session("PopOtherID") Is Nothing) Then
                    Me.dtOtherID = Session("PopOtherID")
                End If
                ''''remove row at...
                dtOtherID.Rows.RemoveAt(index)
                dtOtherID.AcceptChanges()

                ''''bind data again
                grdOtherID.DataSource = dtOtherID
                grdOtherID.DataBind()
                ''''จำนวนแถว ''''''''''''''''''''''''''''''''''''''
                Me.lblCount_Oth_Doc.Text = Me.dtOtherID.Rows.Count
                ''''''''''''''''''''''''''''''''''''''''''''''''''
                ''''deselect 
                grdOtherID.SelectedIndex = -1

                Me.lblAuthor_Req_Oth_Doc.Text = "Y"

            End If

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Page,
                                                Page.GetType(),
                                                "clientScript",
                                                "alert('" + ex.Message.Replace("'", "") + "')",
                                                True)
        End Try
    End Sub

    Sub Delete_gridRow_grdNation()

        Try

            Dim index As Integer = grdNaiton.SelectedIndex
            If index = -1 Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('ต้องเลือกสัญชาติที่ต้องการลบก่อน')", True)
            Else

                'check session of data table
                If Not (Session("PopNation") Is Nothing) Then
                    dtNation = Session("PopNation")
                End If
                ''''remove row at...
                dtNation.Rows.RemoveAt(index)
                dtNation.AcceptChanges()

                ''''bind data again
                grdNaiton.DataSource = dtNation
                grdNaiton.DataBind()
                '''''Number of Rows ''''''''''''''''''''''''''
                lblCount_Nation.Text = Me.dtNation.Rows.Count
                ''''''''''''''''''''''''''''''''''''''''''''''
                ''''deselect '''''''''''''''
                grdNaiton.SelectedIndex = -1
                ''''''''''''''''''''''''''''
                Me.lblAuthor_Req_Nation.Text = "Y"

            End If

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Page,
                                                Page.GetType(),
                                                "clientScript",
                                                "alert('" + ex.Message.Replace("'", "") + "')",
                                                True)
        End Try
    End Sub

    Sub Delete_gridRow_grdPolitical()
        Try

            Dim index As Integer = grdPolitical.SelectedIndex
            If index = -1 Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('ต้องเลือกชื่อนักการเมืองที่ต้องการลบก่อน')", True)
            Else
                'check session of data table
                If Not (Session("PopPolitical") Is Nothing) Then
                    Me.dtPolitical = Session("PopPolitical")
                End If
                ''''remove row at...
                dtPolitical.Rows.RemoveAt(index)
                dtPolitical.AcceptChanges()

                ''''bind data again
                grdPolitical.DataSource = dtPolitical
                grdPolitical.DataBind()
                ''''Number of Rows '''''''''''''''''''''''''''''''''' 
                Me.lblCount_Politic.Text = Me.dtPolitical.Rows.Count
                '''''''''''''''''''''''''''''''''''''''''''''''''''''
                ''''deselect''''''''''''''''''''' 
                grdPolitical.SelectedIndex = -1
                '''''''''''''''''''''''''''''''''
                Me.lblAuthor_Req_Politic.Text = "Y"

            End If

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Page,
                                                Page.GetType(),
                                                "clientScript",
                                                "alert('" + ex.Message.Replace("'", "") + "')",
                                                True)
        End Try
    End Sub

    Sub Delete_gridRow_grdOcc()
        Dim clsDropDown As New clsMasterDropDown
        Try

            Dim index As Integer = grdOcc.SelectedIndex
            If index = -1 Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('ต้องเลือกอาชีพที่ต้องการลบก่อน')", True)
            Else
                'check session of data table
                If Not (Session("PopOcc") Is Nothing) Then
                    Me.dtOcc = Session("PopOcc")
                End If
                ''''remove row at...
                dtOcc.Rows.RemoveAt(index)
                dtOcc.AcceptChanges()

                ''''bind data again
                grdOcc.DataSource = dtOcc
                grdOcc.DataBind()
                ''''Number of Rows '''''''''''''''''''''''
                Me.lblCount_OCC.Text = Me.dtOcc.Rows.Count
                ''''''''''''''''''''''''''''''''''''''''''
                ''''deselect '''''''''''''''
                grdOcc.SelectedIndex = -1

                clsDropDown.setOccupationToDdl(ddlOccupation1, 1)
                Me.txtOccOther1.Text = ""
                Me.txtBizOther1.Text = ""
                ddlOccupation4.Items.Clear()
                ''''''''''''''''''''''''''''
                Me.lblAuthor_Req_Occupation.Text = "Y"

            End If

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Page,
                                                Page.GetType(),
                                                "clientScript",
                                                "alert('" + ex.Message.Replace("'", "") + "')",
                                                True)
        End Try

    End Sub

    Sub Delete_gridRow_grdIncome()
        Try

            Dim index As Integer = grdIncome.SelectedIndex
            If index = -1 Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('ต้องเลือกแหล่งที่มาของรายได้ที่ต้องการลบก่อน')", True)
            Else
                'check session of data table
                If Not (Session("PopINCOME") Is Nothing) Then
                    Me.dtIncome = Session("PopINCOME")
                End If
                ''''remove row at...
                dtIncome.Rows.RemoveAt(index)
                dtIncome.AcceptChanges()

                ''''bind data again
                grdIncome.DataSource = Me.dtIncome
                grdIncome.DataBind()
                ''''Number of Rows ''''''''''''''''''''''''''''''''''
                Me.lblCount_Inc_Source.Text = Me.dtIncome.Rows.Count
                '''''''''''''''''''''''''''''''''''''''''''''''''''''

                ''''deselect ''''''''''''''''
                grdIncome.SelectedIndex = -1
                '''''''''''''''''''''''''''''
            End If

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Page,
                                                Page.GetType(),
                                                "clientScript",
                                                "alert('" + ex.Message.Replace("'", "") + "')",
                                                True)
        End Try
    End Sub


    Sub Delete_grdRow_grdBO()
        Try

            If Validate_Acct_BO_Delete() = False Then Exit Sub

            Dim index As Integer = grdBo.SelectedIndex
            If index = -1 Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('ต้องเลือก BO ที่ต้องการลบก่อน')", True)
            Else

                'check session of data table
                If Not (Session("PopBo") Is Nothing) Then
                    Me.dtBo = Session("PopBo")
                End If
                ''''remove row at...
                dtBo.Rows.RemoveAt(index)
                dtBo.AcceptChanges()

                ''''bind data again
                grdBo.DataSource = dtBo
                grdBo.DataBind()
                ''''Number of Rows '''''''''''''''''''''
                Me.lblCount_BO.Text = Me.dtBo.Rows.Count
                ''''''''''''''''''''''''''''''''''''''''
                ''''deselect '''''''''''
                grdBo.SelectedIndex = -1
                '''''''''''''''''''''''''


            End If

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Page,
                                                Page.GetType(),
                                                "clientScript",
                                                "alert('" + ex.Message.Replace("'", "") + "')",
                                                True)
        End Try
    End Sub

    Sub Delete_grdRow_grdFamily()

        Try

            Dim index As Integer = grdFamily.SelectedIndex
            If index = -1 Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('ต้องเลือกข้อมูลบุคคลในครอบครัวที่ต้องการลบก่อน')", True)
            Else
                'check session of data table
                If Not (Session("PopFamily") Is Nothing) Then
                    Me.dtFamily = Session("PopFamily")
                End If
                ''''remove row at...
                dtFamily.Rows.RemoveAt(index)
                dtFamily.AcceptChanges()

                ''''bind data again
                grdFamily.DataSource = dtFamily
                grdFamily.DataBind()
                ''''Number of Rows '''''''''''''''''''''''''''
                Me.lblCount_Family.Text = Me.dtFamily.Rows.Count
                ''''''''''''''''''''''''''''''''''''''''''''''
                ''''deselect '''''''''''''''' 
                grdFamily.SelectedIndex = -1
                '''''''''''''''''''''''''''''
            End If

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Page,
                                                Page.GetType(),
                                                "clientScript",
                                                "alert('" + ex.Message.Replace("'", "") + "')",
                                                True)
        End Try
    End Sub



#End Region

#Region "Grid checkActive"

    Protected Sub chActivePassport_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)

        ''''check Session ''''''''''''''''''''''
        If Not (Session("PopPassport") Is Nothing) Then
            Me.dtPassport = Session("PopPassport")
        End If

        '''''' assign checkbox value to data table 
        For i = 0 To grdPassport.Rows.Count - 1
            Me.dtPassport.Rows(i).Item("ACTIVE") = CType(grdPassport.Rows(i).Cells(4).FindControl("chActivePassport"), CheckBox).Checked
        Next i

        Me.dtPassport.AcceptChanges()
        grdPassport.DataSource = Me.dtPassport
        grdPassport.DataBind()

        Session("PopPassport") = Me.dtPassport

    End Sub

    Protected Sub chACT_OTH_DOC_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)

        ''''check Session ''''''''''''''''''''''
        If Not (Session("PopOtherID") Is Nothing) Then
            Me.dtOtherID = Session("PopOtherID")
        End If

        '''''' assign checkbox value to data table 
        For i = 0 To Me.grdOtherID.Rows.Count - 1
            Me.dtOtherID.Rows(i).Item("ACTIVE") = CType(Me.grdOtherID.Rows(i).Cells(4).FindControl("chACT_OTH_DOC"), CheckBox).Checked
        Next i

        Me.dtOtherID.AcceptChanges()
        Me.grdOtherID.DataSource = Me.dtOtherID
        Me.grdOtherID.DataBind()

        Session("PopOtherID") = Me.dtOtherID

    End Sub

    Protected Sub chActive_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)

        ''''check Session ''''''''''''''''''''''
        If Not (Session("PopNation") Is Nothing) Then
            dtNation = Session("PopNation")
        End If

        '''''' assign checkbox value to data table 
        For i = 0 To grdNaiton.Rows.Count - 1
            dtNation.Rows(i).Item("ACTIVE") = CType(grdNaiton.Rows(i).Cells(3).FindControl("chActive"), CheckBox).Checked
        Next i

        dtNation.AcceptChanges()
        grdNaiton.DataSource = dtNation
        grdNaiton.DataBind()

        Session("PopNation") = dtNation

    End Sub

    Protected Sub chk_ACT_POLTIC_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)

        ''''check Session ''''''''''''''''''''''
        If Not (Session("PopPolitical") Is Nothing) Then
            Me.dtPolitical = Session("PopPolitical")
        End If

        '''''' assign checkbox value to data table 
        For i = 0 To Me.grdPolitical.Rows.Count - 1
            Me.dtPolitical.Rows(i).Item("ACTIVE") = CType(Me.grdPolitical.Rows(i).Cells(6).FindControl("chk_ACT_POLTIC"), CheckBox).Checked
        Next i

        Me.dtPolitical.AcceptChanges()
        Me.grdPolitical.DataSource = Me.dtPolitical
        Me.grdPolitical.DataBind()

        Session("PopPolitical") = Me.dtPolitical

    End Sub

    Protected Sub chkACT_OCCUPATION_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)

        ''''check Session ''''''''''''''''''''''
        If Not (Session("PopOcc") Is Nothing) Then
            Me.dtOcc = Session("PopOcc")
        End If

        '''''' assign checkbox value to data table 
        For i = 0 To Me.grdOcc.Rows.Count - 1
            Me.dtOcc.Rows(i).Item("ACTIVE") = CType(Me.grdOcc.Rows(i).Cells(7).FindControl("chkACT_OCCUPATION"), CheckBox).Checked
        Next i

        Me.dtOcc.AcceptChanges()
        Me.grdOcc.DataSource = Me.dtOcc
        Me.grdOcc.DataBind()

        Session("PopOcc") = Me.dtOcc

    End Sub

    Protected Sub chk_ACT_INC_SOURCE_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        ''''check Session ''''''''''''''''''''''
        If Not (Session("PopINCOME") Is Nothing) Then
            Me.dtIncome = Session("PopINCOME")
        End If

        '''''' assign checkbox value to data table 
        For i = 0 To Me.grdIncome.Rows.Count - 1
            Me.dtIncome.Rows(i).Item("ACTIVE") = CType(Me.grdIncome.Rows(i).Cells(3).FindControl("chk_ACT_INC_SOURCE"), CheckBox).Checked
        Next i

        Me.dtIncome.AcceptChanges()
        Me.grdIncome.DataSource = Me.dtIncome
        Me.grdIncome.DataBind()

        Session("PopINCOME") = Me.dtIncome

    End Sub

    Protected Sub chk_ACT_CUST_BO_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)

        ''''check Session ''''''''''''''''''''''
        If Not (Session("PopBO") Is Nothing) Then
            Me.dtBo = Session("PopBO")
        End If

        '''''' assign checkbox value to data table 
        For i = 0 To Me.grdBo.Rows.Count - 1
            Me.dtBo.Rows(i).Item("ACTIVE") = CType(Me.grdBo.Rows(i).Cells(10).FindControl("chk_ACT_CUST_BO"), CheckBox).Checked
        Next i

        Me.dtBo.AcceptChanges()
        Me.grdBo.DataSource = Me.dtBo
        Me.grdBo.DataBind()

        Session("PopBO") = Me.dtBo

    End Sub

    Protected Sub chk_ACT_FAM_RELATE_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)

        ''''check Session ''''''''''''''''''''''
        If Not (Session("PopFamily") Is Nothing) Then
            Me.dtFamily = Session("PopFamily")
        End If

        '''''' assign checkbox value to data table 
        For i = 0 To Me.grdFamily.Rows.Count - 1
            Me.dtFamily.Rows(i).Item("ACTIVE") = CType(Me.grdFamily.Rows(i).Cells(14).FindControl("chk_ACT_FAM_RELATE"), CheckBox).Checked
        Next i

        Me.dtFamily.AcceptChanges()
        Me.grdFamily.DataSource = Me.dtFamily
        Me.grdFamily.DataBind()

        Session("PopFamily") = Me.dtFamily

    End Sub

    Protected Sub chk_ACT_REASON_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)

        ''''check Session ''''''''''''''''''''''
        If Not (Session("PopReason") Is Nothing) Then
            Me.dtReason = Session("PopReason")
        End If

        '''''' assign checkbox value to data table 
        For i = 0 To Me.grdReason.Rows.Count - 1
            Me.dtReason.Rows(i).Item("ACTIVE") = CType(Me.grdReason.Rows(i).Cells(4).FindControl("chk_ACT_REASON"), CheckBox).Checked
        Next i

        Me.dtReason.AcceptChanges()
        Me.grdReason.DataSource = Me.dtReason
        Me.grdReason.DataBind()

        Session("PopReason") = Me.dtReason


    End Sub

#End Region

#Region "Bind data to grid"

    Sub Bind_Data_togrid_Passport()

        '''' Connect Data to Grid '''''''''''

        Me.dtPassport.Columns.Add("PASSPORT_NO")
        Me.dtPassport.Columns.Add("ISSUE_DATE")
        Me.dtPassport.Columns.Add("EXPIRE_DATE")

        Me.dtPassport.Columns.Add("FILTER_RESULT")
        Me.dtPassport.Columns.Add("RISK_LEVEL")

        Me.dtPassport.Columns.Add("ACTIVE")

        Dim lvsCustType As Integer = Session("KYC")

        Dim QryPassport = (From tbName In KYCEntity.MCUST_PASSPORT
                          Where tbName.CUSTSEQ = CustSeq
                         Select tbName.SEQ,
                                tbName.PASSPORT_NO,
                                tbName.ISSUE_DATE,
                                tbName.EXPIRE_DATE,
                                tbName.FILTER_RESULT,
                                tbName.RISK_LEVEL,
                                ACTIVE = If(tbName.ACTIVE = "Y", True, False)
                       Order By SEQ)

        For Each mRow In QryPassport
            Me.dtPassport.Rows.Add(mRow.PASSPORT_NO,
                                   mRow.ISSUE_DATE,
                                   mRow.EXPIRE_DATE,
                                   mRow.FILTER_RESULT,
                                   mRow.RISK_LEVEL,
                                   mRow.ACTIVE)

            Me.dtPassport.AcceptChanges()
        Next

        Me.lblCount_Passport.Text = dtPassport.Rows.Count

        Me.grdPassport.DataSource = Me.dtPassport
        Me.grdPassport.DataBind()
        Session("PopPassport") = Me.dtPassport


    End Sub

    Sub Bind_Data_togrid_grdOtherID()

        '''' Connect Data to Grid '''''''''''

        Me.dtOtherID.Columns.Add("OTH_DOC_NAME")
        Me.dtOtherID.Columns.Add("OTH_DOC_ID")
        Me.dtOtherID.Columns.Add("OTH_DOC_CARDID")
        Me.dtOtherID.Columns.Add("ACTIVE")

        Dim lvsCustType As Integer = Session("KYC")

        Dim QryOthDoc = (From tbName In KYCEntity.MCUST_OTH_DOC
                           Where tbName.CUSTSEQ = CustSeq
                          Select tbName.SEQ,
                                 tbName.OTH_DOC_NAME,
                                 tbName.OTH_DOC_ID,
                                 tbName.OTH_DOC_CARDID,
                                 ACTIVE = If(tbName.ACTIVE = "Y", True, False) Order By SEQ)

        For Each mRow In QryOthDoc
            Me.dtOtherID.Rows.Add(mRow.OTH_DOC_NAME,
                                  mRow.OTH_DOC_ID,
                                  mRow.OTH_DOC_CARDID,
                                  mRow.ACTIVE)

            Me.dtOtherID.AcceptChanges()
        Next

        Me.grdOtherID.DataSource = Me.dtOtherID
        Me.grdOtherID.DataBind()

        ''''จำนวนแถว ''''''''''''''''''''''''''''''''''''''
        Me.lblCount_Oth_Doc.Text = Me.dtOtherID.Rows.Count
        ''''''''''''''''''''''''''''''''''''''''''''''''''

        Session("PopOtherID") = Me.dtOtherID


    End Sub

    Sub Bind_Data_togrid_Nation()

        '''' Connect Data to Grid '''''''''''RISK_LEVEL

        dtNation.Columns.Add("NATION_NAME")
        dtNation.Columns.Add("NATIONALITY")
        dtNation.Columns.Add("RISK_LEVEL")
        dtNation.Columns.Add("ACTIVE")

        Dim lvsCustType As Integer = Session("KYC")

        Dim qryNation = (From tbName In KYCEntity.MCUST_NATION
                        Where tbName.CUSTSEQ = CustSeq
                       Select tbName.SEQ,
                              tbName.NATIONALITY,
                              tbName.NATION_NAME,
                              tbName.RISK_LEVEL,
                              ACTIVE = If(tbName.ACTIVE = "Y", True, False)
                     Order By SEQ)

        For Each mRow In qryNation
            dtNation.Rows.Add(mRow.NATION_NAME,
                              mRow.NATIONALITY,
                              mRow.RISK_LEVEL,
                              mRow.ACTIVE)
            dtNation.AcceptChanges()
        Next

        Me.grdNaiton.DataSource = dtNation
        Me.grdNaiton.DataBind()
        '''''Number of Rows ''''''''''''''''''''''''''
        lblCount_Nation.Text = Me.dtNation.Rows.Count
        ''''''''''''''''''''''''''''''''''''''''''''''
        Session("PopNation") = dtNation

    End Sub

    Sub Bind_Data_togrid_grdPolitical()

        '''' Connect Data to Grid '''''''''''
        Me.dtPolitical.Columns.Add("THPREFIX")
        Me.dtPolitical.Columns.Add("THPREFIX_DESC")
        Me.dtPolitical.Columns.Add("THFIRSTNAME")
        Me.dtPolitical.Columns.Add("THMIDNAME")
        Me.dtPolitical.Columns.Add("THLASTNAME")

        Me.dtPolitical.Columns.Add("ENPREFIX")
        Me.dtPolitical.Columns.Add("ENPREFIX_DESC")
        Me.dtPolitical.Columns.Add("ENFIRSTNAME")
        Me.dtPolitical.Columns.Add("ENMIDNAME")
        Me.dtPolitical.Columns.Add("ENLASTNAME")

        Me.dtPolitical.Columns.Add("POLITIC_POST_CONC")
        Me.dtPolitical.Columns.Add("POLITIC_RELATION")
        Me.dtPolitical.Columns.Add("ACTIVE")

        Dim lvsCustType As Integer = Session("KYC")

        Dim qryPolitic = (From tbName In KYCEntity.MCUST_POLITICIAN_CONCERN
                        Where tbName.CUSTSEQ = CustSeq
                       Select tbName.SEQ,
                              tbName.THPREFIX,
                              tbName.THPREFIX_DESC,
                              tbName.THFIRSTNAME,
                              tbName.THMIDNAME,
                              tbName.THLASTNAME,
                              tbName.ENPREFIX,
                              tbName.ENPREFIX_DESC,
                              tbName.ENFIRSTNAME,
                              tbName.ENMIDNAME,
                              tbName.ENLASTNAME,
                              tbName.POLITIC_RELATION,
                              tbName.POLITIC_POST_CONC,
                              ACTIVE = If(tbName.ACTIVE = "Y", True, False)
                     Order By SEQ)

        For Each mRow In qryPolitic
            Me.dtPolitical.Rows.Add(mRow.THPREFIX,
                                    mRow.THPREFIX_DESC,
                                    mRow.THFIRSTNAME,
                                    mRow.THMIDNAME,
                                    mRow.THLASTNAME,
                                    mRow.ENPREFIX,
                                    mRow.ENPREFIX_DESC,
                                    mRow.ENFIRSTNAME,
                                    mRow.THMIDNAME,
                                    mRow.ENLASTNAME,
                                    mRow.POLITIC_POST_CONC,
                                    mRow.POLITIC_RELATION,
                                    mRow.ACTIVE)
            Me.dtPolitical.AcceptChanges()
        Next

        Me.grdPolitical.DataSource = Me.dtPolitical
        Me.grdPolitical.DataBind()
        ''''Number of Rows '''''''''''''''''''''''''''''''''' 
        Me.lblCount_Politic.Text = Me.dtPolitical.Rows.Count
        '''''''''''''''''''''''''''''''''''''''''''''''''''''
        Session("PopPolitical") = Me.dtPolitical

    End Sub

    Sub Bind_Data_togrid_grdOcc()

        '''' Connect Data to Grid '''''''''''
        Me.dtOcc.Columns.Add("OCC_DESC")
        Me.dtOcc.Columns.Add("OCCCODE")
        Me.dtOcc.Columns.Add("OCC_SUB_DESC")
        Me.dtOcc.Columns.Add("REMARK_T")
        Me.dtOcc.Columns.Add("OCCCODE_SUB")
        Me.dtOcc.Columns.Add("POSITION")
        Me.dtOcc.Columns.Add("RISK")
        Me.dtOcc.Columns.Add("ACTIVE")

        Dim lvsCustType As Integer = Session("KYC")

        Dim qryOcc = (From tbName In KYCEntity.MCUST_OCCUPATION
                        Where tbName.CUSTSEQ = CustSeq
                       Select tbName.SEQ,
                              tbName.OCC_DESC,
                              tbName.OCCCODE,
                              tbName.REMARK_T,
                              tbName.OCC_SUB_DESC,
                              tbName.OCCCODE_SUB,
                              tbName.POSITION,
                              tbName.RISK,
                              ACTIVE = If(tbName.ACTIVE = "Y", True, False)
                     Order By SEQ)

        For Each mRow In qryOcc
            Me.dtOcc.Rows.Add(mRow.OCC_DESC,
                              mRow.OCCCODE,
                              mRow.OCC_SUB_DESC,
                              mRow.REMARK_T,
                              mRow.OCCCODE_SUB,
                              mRow.POSITION,
                              mRow.RISK,
                              mRow.ACTIVE)
            Me.dtOcc.AcceptChanges()
        Next

        Me.grdOcc.DataSource = Me.dtOcc
        Me.grdOcc.DataBind()

        ''''Number of Rows '''''''''''''''''''''''
        Me.lblCount_OCC.Text = Me.dtOcc.Rows.Count
        ''''''''''''''''''''''''''''''''''''''''''
        Session("PopOcc") = Me.dtOcc

    End Sub

    Sub Bind_Data_togrid_Income_Source()

        '''' Connect Data to Grid '''''''''''
        Me.dtIncome.Columns.Add("COUNTYNAME")
        Me.dtIncome.Columns.Add("NATIONCODE")
        Me.dtIncome.Columns.Add("COUNTYNAMETH")
        Me.dtIncome.Columns.Add("RISK_LEVEL")
        Me.dtIncome.Columns.Add("ACTIVE")

        Dim lvsCustType As Integer = Session("KYC")

        Dim QryIncome = (From tbName In KYCEntity.MCUST_INCOME_SOURCE
                        Where tbName.CUSTSEQ = CustSeq
                       Select tbName.SEQ,
                              tbName.COUNTYNAME,
                              tbName.NATIONCODE,
                              tbName.COUNTYNAMETH,
                              tbName.RISK_LEVEL,
                              ACTIVE = If(tbName.ACTIVE = "Y", True, False)
                     Order By SEQ)

        For Each mRow In QryIncome
            Me.dtIncome.Rows.Add(mRow.COUNTYNAME,
                                 mRow.NATIONCODE,
                                 mRow.COUNTYNAMETH,
                                 mRow.RISK_LEVEL,
                                 mRow.ACTIVE)

            Me.dtIncome.AcceptChanges()
        Next

        Me.grdIncome.DataSource = Me.dtIncome
        Me.grdIncome.DataBind()
        ''''Number of Rows ''''''''''''''''''''''''''''''''''
        Me.lblCount_Inc_Source.Text = Me.dtIncome.Rows.Count
        '''''''''''''''''''''''''''''''''''''''''''''''''''''
        Session("PopINCOME") = Me.dtIncome

    End Sub

    Sub Bind_Data_togrid_BO()

        '''' Connect Data to Grid '''''''''''
        Me.dtBo.Columns.Add("CIF_NO")
        Me.dtBo.Columns.Add("UNIQUEID")
        Me.dtBo.Columns.Add("PASSPORT_NO")

        Me.dtBo.Columns.Add("OTH_ID_TYPE")
        Me.dtBo.Columns.Add("OTH_ID_DESC")
        Me.dtBo.Columns.Add("OTH_ID_NO")

        Me.dtBo.Columns.Add("THPREFIX")
        Me.dtBo.Columns.Add("THPREFIX_DESC")
        Me.dtBo.Columns.Add("THFIRSTNAME")
        Me.dtBo.Columns.Add("THMIDNAME")
        Me.dtBo.Columns.Add("THLASTNAME")

        Me.dtBo.Columns.Add("ENPREFIX")
        Me.dtBo.Columns.Add("ENPREFIX_DESC")
        Me.dtBo.Columns.Add("ENFIRSTNAME")
        Me.dtBo.Columns.Add("ENMIDNAME")
        Me.dtBo.Columns.Add("ENLASTNAME")

        Me.dtBo.Columns.Add("ACC_OWN_RELATION")

        Me.dtBo.Columns.Add("FILTER_RESULT")
        Me.dtBo.Columns.Add("RISK_LEVEL")

        Me.dtBo.Columns.Add("ACTIVE")

        Dim lvsCustType As Integer = Session("KYC")

        Dim QryBO = (From tbName In KYCEntity.MCUST_BO
                        Where tbName.CUSTSEQ = CustSeq
                       Select tbName.SEQ,
                              tbName.CIF_NO,
                              tbName.UNIQUEID,
                              tbName.PASSPORT_NO,
                              tbName.OTH_ID_TYPE,
                              tbName.OTH_ID_DESC,
                              tbName.OTH_ID_NO,
                              tbName.THPREFIX,
                              tbName.THPREFIX_DESC,
                              tbName.THFIRSTNAME,
                              tbName.THMIDNAME,
                              tbName.THLASTNAME,
                              tbName.ENPREFIX,
                              tbName.ENPREFIX_DESC,
                              tbName.ENFIRSTNAME,
                              tbName.ENMIDNAME,
                              tbName.ENLASTNAME,
                              tbName.ACC_OWN_RELATION,
                              tbName.FILTER_RESULT,
                              tbName.RISK_LEVEL,
                              ACTIVE = If(tbName.ACTIVE = "Y", True, False)
                     Order By SEQ)

        For Each mRow In QryBO
            Me.dtBo.Rows.Add(mRow.CIF_NO,
                             mRow.UNIQUEID,
                             mRow.PASSPORT_NO,
                             mRow.OTH_ID_TYPE,
                             mRow.OTH_ID_DESC,
                             mRow.OTH_ID_NO,
                             mRow.THPREFIX,
                             mRow.THPREFIX_DESC,
                             mRow.THFIRSTNAME,
                             mRow.THMIDNAME,
                             mRow.THLASTNAME,
                             mRow.ENPREFIX,
                             mRow.ENPREFIX_DESC,
                             mRow.ENFIRSTNAME,
                             mRow.ENMIDNAME,
                             mRow.ENLASTNAME,
                             mRow.ACC_OWN_RELATION,
                             mRow.FILTER_RESULT,
                             mRow.RISK_LEVEL,
                             mRow.ACTIVE)

            Me.dtBo.AcceptChanges()
        Next

        Me.grdBo.DataSource = Me.dtBo
        Me.grdBo.DataBind()
        ''''Number of Rows '''''''''''''''''''''
        Me.lblCount_BO.Text = Me.dtBo.Rows.Count
        ''''''''''''''''''''''''''''''''''''''''
        Session("PopBo") = Me.dtBo

    End Sub

    Sub Bind_Data_togrid_Sanction()


        '''' Connect Data to Grid '''''''''''
        Me.dtSanc.Columns.Add("SELECTLIST")
        Me.dtSanc.Columns.Add("ENTITY_ID")
        Me.dtSanc.Columns.Add("UNIQUEID")

        Me.dtSanc.Columns.Add("FIRST_NAME")
        Me.dtSanc.Columns.Add("MIDDLE_NAME")
        Me.dtSanc.Columns.Add("SURNAME")
        Me.dtSanc.Columns.Add("FULLNAME")

        Me.dtSanc.Columns.Add("FIRSTNAME_E")
        Me.dtSanc.Columns.Add("MIDDLE_NAME_E")
        Me.dtSanc.Columns.Add("SURNAME_E")
        Me.dtSanc.Columns.Add("ORIGINAL_SCRIPT_NAME")

        Me.dtSanc.Columns.Add("BIRTHINFO_DATE")
        Me.dtSanc.Columns.Add("DATASOURCE")
        Me.dtSanc.Columns.Add("COUNTRY_DESC")
        Me.dtSanc.Columns.Add("LastUpdateDate")

        Dim lvsCustType As Integer = Session("KYC")

        Dim QrySanct = (From tbName In KYCEntity.MCUST_SANC_LIST
                        Where tbName.CUSTSEQ = CustSeq
                       Select tbName.SEQ,
                              tbName.CHKLIST,
                              tbName.ENTITY_ID,
                              tbName.UNIQUEID,
                              tbName.FIRST_NAME,
                              tbName.MIDDLE_NAME,
                              tbName.SURNAME,
                              tbName.FIRSTNAME_E,
                              tbName.MIDDLE_NAME_E,
                              tbName.SURNAME_E,
                              tbName.FULLNAME,
                              tbName.DATASOURCE,
                              tbName.ORIGINAL_SCRIPT_NAME,
                              tbName.COUNTRY_DESC,
                              tbName.BIRTHINFO_DATE,
                              LastUpdateDate = tbName.SANC_UPDATE_DATE,
                              SELECTLIST = If(tbName.CHKLIST = "Y", True, False)
                     Order By SEQ)

        For Each mRow In QrySanct
            Me.dtSanc.Rows.Add(mRow.SELECTLIST,
                               mRow.ENTITY_ID,
                               mRow.UNIQUEID,
                               mRow.FIRST_NAME,
                               mRow.MIDDLE_NAME,
                               mRow.SURNAME,
                               mRow.FULLNAME,
                               mRow.FIRSTNAME_E,
                               mRow.MIDDLE_NAME_E,
                               mRow.SURNAME_E,
                               mRow.ORIGINAL_SCRIPT_NAME,
                               mRow.BIRTHINFO_DATE,
                               mRow.DATASOURCE,
                               mRow.COUNTRY_DESC,
                               mRow.LastUpdateDate)

            Me.dtSanc.AcceptChanges()
        Next

        Me.grdList.DataSource = Me.dtSanc
        Me.grdList.DataBind()
        ''''Number of Rows '''''''''''''''''''''
        Me.lblCount_Sanct.Text = Me.dtSanc.Rows.Count
        ''''''''''''''''''''''''''''''''''''''''
        Session("PopSanc") = Me.dtSanc

    End Sub

    Sub Bind_Data_togrid_CustName()

        '''' Connect Data to Grid '''''''''''
        Me.dtCustName.Columns.Add("UNIQUEID")
        Me.dtCustName.Columns.Add("PASSPORT_NO")

        Me.dtCustName.Columns.Add("THPREFIX")
        Me.dtCustName.Columns.Add("THPREFIX_DESC")
        Me.dtCustName.Columns.Add("THFIRSTNAME")
        Me.dtCustName.Columns.Add("THMIDNAME")
        Me.dtCustName.Columns.Add("THLASTNAME")

        Me.dtCustName.Columns.Add("ENPREFIX")
        Me.dtCustName.Columns.Add("ENPREFIX_DESC")
        Me.dtCustName.Columns.Add("ENFIRSTNAME")
        Me.dtCustName.Columns.Add("ENMIDNAME")
        Me.dtCustName.Columns.Add("ENLASTNAME")

        Me.dtCustName.Columns.Add("USER_CREATED_DATE")
        Me.dtCustName.Columns.Add("USER_CREATED_BY")
        Me.dtCustName.Columns.Add("ACTIVE")

        Dim lvsCustType As Integer = Session("KYC")

        Dim QryCustName = (From tbName In KYCEntity.MCUST_NAME
                        Where tbName.CUSTSEQ = CustSeq
                       Select tbName.SEQ,
                              tbName.UNIQUEID,
                              tbName.PASSPORT_NO,
                              tbName.THPREFIX,
                              tbName.THPREFIX_DESC,
                              tbName.THFIRSTNAME,
                              tbName.THMIDNAME,
                              tbName.ENPREFIX,
                              tbName.ENPREFIX_DESC,
                              tbName.THLASTNAME,
                              tbName.ENFIRSTNAME,
                              tbName.ENMIDNAME,
                              tbName.ENLASTNAME,
                              tbName.USER_CREATED_DATE,
                              tbName.USER_CREATED_BY,
                              ACTIVE = If(tbName.ACTIVE = "Y", True, False)
                     Order By SEQ)

        For Each mRow In QryCustName
            Me.dtCustName.Rows.Add(mRow.UNIQUEID,
                             mRow.PASSPORT_NO,
                             mRow.THPREFIX,
                             mRow.THPREFIX_DESC,
                             mRow.THFIRSTNAME,
                             mRow.THMIDNAME,
                             mRow.THLASTNAME,
                             mRow.ENPREFIX,
                             mRow.ENPREFIX_DESC,
                             mRow.ENFIRSTNAME,
                             mRow.THMIDNAME,
                             mRow.ENLASTNAME,
                             mRow.USER_CREATED_DATE,
                             mRow.USER_CREATED_BY,
                             mRow.ACTIVE)



            Me.dtCustName.AcceptChanges()
        Next

        Me.grdCust_NAME.DataSource = Me.dtCustName
        Me.grdCust_NAME.DataBind()
        ''''Number of Rows '''''''''''''''''''''
        Me.lblCount_Name.Text = Me.dtCustName.Rows.Count
        ''''''''''''''''''''''''''''''''''''''''
        Session("PopCustName") = Me.dtCustName

    End Sub

    Protected Sub btnAdd_CustName_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd_CustName.Click
        Add_To_grid_CustName()
    End Sub

    Sub Add_To_grid_CustName()

        If Me.Validate_Custname = False Then Exit Sub

        Dim strUser As String = clsSessionMenuRight.getUserName

        'check session of data table
        If Not (Session("PopCustName") Is Nothing) Then
            Me.dtCustName = Session("PopCustName")
        End If

        '''''''' insert data to grid row '''''''''''''''''''''''''''''''''''''''''''''''''
        dtCustName.Rows.Add(Me.txtUniqueID.Text,
                            Me.txtPASSPORT_NO.Text,
                            Me.ddlPrefixTH.SelectedIndex,
                            Me.ddlPrefixTH.SelectedItem,
                            Me.txtNameTh1.Text,
                            Me.txtNameTh2.Text,
                            Me.txtNameTh3.Text,
                            Me.ddlPrefixEN.SelectedIndex,
                            Me.ddlPrefixEN.SelectedItem,
                            Me.txtNameEn1.Text,
                            Me.txtNameEn2.Text,
                            Me.txtNameEn3.Text,
                            Now,
                            strUser,
                            True)

        dtCustName.AcceptChanges()
        Me.grdCust_NAME.DataSource = dtCustName
        Me.grdCust_NAME.DataBind()
        ''''Number of Rows '''''''''''''''''''''
        Me.lblCount_Name.Text = Me.dtCustName.Rows.Count
        ''''''''''''''''''''''''''''''''''''''''
        ''''deselect '''''''''''''''
        Me.grdCust_NAME.SelectedIndex = -1
        ''''''''''''''''''''''''''''

        'now bind datatable to gridview... 
        Session("PopCustName") = Me.dtCustName

        '''''Clear Screen '''''''''''''''
        Me.txtNameTh1.Focus()

    End Sub

    Protected Sub btnDel_CustName_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDel_CustName.Click
        Me.Delete_grdRow_grdCustName()
    End Sub

    Sub Delete_grdRow_grdCustName()
        Try

            Dim index As Integer = Me.grdCust_NAME.SelectedIndex
            If index = -1 Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('ต้องเลือกแถวที่ต้องการลบก่อน')", True)
            Else

                'check session of data table
                If Not (Session("PopCustName") Is Nothing) Then
                    Me.dtCustName = Session("PopCustName")
                End If
                ''''remove row at...
                dtCustName.Rows.RemoveAt(index)
                dtCustName.AcceptChanges()

                ''''bind data again
                Me.grdCust_NAME.DataSource = dtCustName
                Me.grdCust_NAME.DataBind()
                ''''Number of Rows '''''''''''''''''''''
                Me.lblCount_Name.Text = Me.dtCustName.Rows.Count
                ''''''''''''''''''''''''''''''''''''''''
                ''''deselect '''''''''''
                Me.grdCust_NAME.SelectedIndex = -1
                '''''''''''''''''''''''''

            End If

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Page,
                                                Page.GetType(),
                                                "clientScript",
                                                "alert('" + ex.Message.Replace("'", "") + "')",
                                                True)
        End Try
    End Sub

    Protected Sub chkACT_CUST_NAME_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        ''''check Session ''''''''''''''''''''''
        If Not (Session("PopCustName") Is Nothing) Then
            Me.dtCustName = Session("PopCustName")
        End If

        '''''' assign checkbox value to data table 
        For i = 0 To Me.grdCust_NAME.Rows.Count - 1
            Me.dtCustName.Rows(i).Item("ACTIVE") = CType(Me.grdCust_NAME.Rows(i).Cells(11).FindControl("chkACT_CUST_NAME"), CheckBox).Checked
        Next i

        Me.dtCustName.AcceptChanges()
        Me.grdCust_NAME.DataSource = Me.dtCustName
        Me.grdCust_NAME.DataBind()

        Session("PopCustName") = Me.dtCustName
    End Sub


    Sub Bind_Data_togrid_Family()

        '''' Connect Data to Grid '''''''''''
        Me.dtFamily.Columns.Add("CIF_NO")
        Me.dtFamily.Columns.Add("UNIQUEID")
        Me.dtFamily.Columns.Add("PASSPORT_NO")

        Me.dtFamily.Columns.Add("OTH_ID_TYPE")
        Me.dtFamily.Columns.Add("OTH_ID_DESC")
        Me.dtFamily.Columns.Add("OTH_ID_NO")

        Me.dtFamily.Columns.Add("THPREFIX")
        Me.dtFamily.Columns.Add("THPREFIX_DESC")
        Me.dtFamily.Columns.Add("THFIRSTNAME")
        Me.dtFamily.Columns.Add("THMIDNAME")
        Me.dtFamily.Columns.Add("THLASTNAME")

        Me.dtFamily.Columns.Add("ENPREFIX")
        Me.dtFamily.Columns.Add("ENPREFIX_DESC")
        Me.dtFamily.Columns.Add("ENFIRSTNAME")
        Me.dtFamily.Columns.Add("ENMIDNAME")
        Me.dtFamily.Columns.Add("ENLASTNAME")

        Me.dtFamily.Columns.Add("CUST_RELATION")

        Me.dtFamily.Columns.Add("FILTER_RESULT")
        Me.dtFamily.Columns.Add("RISK_LEVEL")
        Me.dtFamily.Columns.Add("ACTIVE")

        Dim lvsCustType As Integer = Session("KYC")

        Dim QryFamily = (From tbName In KYCEntity.MCUST_FAMILY
                        Where tbName.CUSTSEQ = CustSeq
                       Select tbName.SEQ,
                              tbName.CIF_NO,
                              tbName.UNIQUEID,
                              tbName.PASSPORT_NO,
                              tbName.OTH_ID_TYPE,
                              tbName.OTH_ID_DESC,
                              tbName.OTH_ID_NO,
                              tbName.THPREFIX,
                              tbName.THPREFIX_DESC,
                              tbName.THFIRSTNAME,
                              tbName.THMIDNAME,
                              tbName.THLASTNAME,
                              tbName.ENPREFIX,
                              tbName.ENPREFIX_DESC,
                              tbName.ENFIRSTNAME,
                              tbName.ENMIDNAME,
                              tbName.ENLASTNAME,
                              tbName.CUST_RELATION,
                              tbName.FILTER_RESULT,
                              tbName.RISK_LEVEL,
                              ACTIVE = If(tbName.ACTIVE = "Y", True, False)
                     Order By SEQ)

        For Each mRow In QryFamily
            Me.dtFamily.Rows.Add(mRow.CIF_NO,
                                 mRow.UNIQUEID,
                                 mRow.PASSPORT_NO,
                                 mRow.OTH_ID_TYPE,
                                 mRow.OTH_ID_DESC,
                                 mRow.OTH_ID_NO,
                                 mRow.THPREFIX,
                                 mRow.THPREFIX_DESC,
                                 mRow.THFIRSTNAME,
                                 mRow.THMIDNAME,
                                 mRow.THLASTNAME,
                                 mRow.ENPREFIX,
                                 mRow.ENPREFIX_DESC,
                                 mRow.ENFIRSTNAME,
                                 mRow.ENMIDNAME,
                                 mRow.ENLASTNAME,
                                 mRow.CUST_RELATION,
                                 mRow.FILTER_RESULT,
                                 mRow.RISK_LEVEL,
                                 mRow.ACTIVE)

            Me.dtFamily.AcceptChanges()
        Next

        Me.grdFamily.DataSource = Me.dtFamily
        Me.grdFamily.DataBind()

        ''''Number of Rows '''''''''''''''''''''''''''
        Me.lblCount_Family.Text = Me.dtFamily.Rows.Count
        ''''''''''''''''''''''''''''''''''''''''''''''

        Session("PopFamily") = Me.dtFamily

    End Sub

    Sub Bind_Data_togrid_Reason()

        '''' Connect Data to Grid '''''''''''
        Me.dtReason.Columns.Add("REASONS")
        Me.dtReason.Columns.Add("USER_CREATED_DATE")
        Me.dtReason.Columns.Add("USER_CREATED_BY")
        Me.dtReason.Columns.Add("ACTIVE")

        Dim lvsCustType As Integer = Session("KYC")

        Dim qryReason = (From tbName In KYCEntity.MCUST_REASON
                        Where tbName.CUSTSEQ = CustSeq
                       Select tbName.SEQ,
                              tbName.USER_CREATED_DATE,
                              tbName.USER_CREATED_BY,
                              tbName.REASONS,
                              ACTIVE = If(tbName.ACTIVE = "Y", True, False)
                     Order By SEQ)

        For Each mRow In qryReason
            Me.dtReason.Rows.Add(mRow.REASONS,
                                 mRow.USER_CREATED_DATE,
                                 mRow.USER_CREATED_BY,
                                 mRow.ACTIVE)

            Me.dtReason.AcceptChanges()
        Next

        Me.grdReason.DataSource = Me.dtReason
        Me.grdReason.DataBind()
        ''''Number of Rows''''''''''''''''''''''''''''''
        Me.lblCount_Reason.Text = Me.dtReason.Rows.Count
        ''''''''''''''''''''''''''''''''''''''''''''''''
        Session("PopReason") = Me.dtReason

    End Sub
#End Region


    Protected Sub btnVALIDATE_IDCARD_NO_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnVALIDATE_IDCARD_NO.Click
        'clsCheckID = New clsCheckID
        'If clsValid.CheckNull(Me.txtUniqueID) = False Then Exit Sub
        'If clsCheckID.checkUniqueID1(txtUniqueID.Text, TypeKYC, CustSeq) = False Then
        '    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('เลขบัตรประชาขนไม่ถูกต้อง');", True)
        '    Me.txtUniqueID.Focus()
        'End If
        Session("chkKYC") = Nothing

    End Sub

#Region "Smart Card"

    Sub Find_SmartCard_for_Customer(ByVal Citizen_ID As String)

        Try

            Dim dtSmartCard As DataTable = New DataTable


            If Citizen_ID = "" Then Exit Sub
            If Len(Citizen_ID) <> 13 Then Exit Sub


            lvsSQL = ""
            lvsSQL += "     SELECT FIRST_NAME,                          "
            lvsSQL += "            LAST_NAME,                           "
            lvsSQL += "            FIRST_NAME_EN,                       "
            lvsSQL += "            LAST_NAME_EN,                        "
            lvsSQL += "            BIRTH_DATE,                          "
            lvsSQL += "            START_DATE                           "
            lvsSQL += "       FROM KYCADMIN.GHB_BORAINTERFACE           "
            lvsSQL += "      WHERE CITIZEN_ID = '" & Citizen_ID & "'    "
            dtSmartCard = clsDatabase.QueryDataTable(lvsSQL)

            If (dtSmartCard.Rows.Count <> 0) Then

                If Not IsDBNull(dtSmartCard.Rows(0)("FIRST_NAME")) Then Me.txtNameTh1.Text = dtSmartCard.Rows(0)("FIRST_NAME")
                If Not IsDBNull(dtSmartCard.Rows(0)("LAST_NAME")) Then Me.txtNameTh3.Text = dtSmartCard.Rows(0)("LAST_NAME")

                If Not IsDBNull(dtSmartCard.Rows(0)("FIRST_NAME_EN")) Then Me.txtNameEn1.Text = dtSmartCard.Rows(0)("FIRST_NAME_EN")
                If Not IsDBNull(dtSmartCard.Rows(0)("LAST_NAME_EN")) Then Me.txtNameEn3.Text = dtSmartCard.Rows(0)("LAST_NAME_EN")


                Me.txtBIRTH_DATE_TH_DD.Text = Mid(dtSmartCard.Rows(0)("BIRTH_DATE"), 1, 2)
                Me.txtBIRTH_DATE_TH_MM.Text = Mid(dtSmartCard.Rows(0)("BIRTH_DATE"), 3, 2)
                Me.txtBIRTH_DATE_TH_YYYY.Text = Mid(dtSmartCard.Rows(0)("BIRTH_DATE"), 5, 4)

                Me.txtID_CARD_ISSUE_DD.Text = Mid(dtSmartCard.Rows(0)("START_DATE"), 1, 2)
                Me.txtID_CARD_ISSUE_MM.Text = Mid(dtSmartCard.Rows(0)("START_DATE"), 3, 2)
                Me.txtID_CARD_ISSUE_YYYY.Text = Mid(dtSmartCard.Rows(0)("START_DATE"), 5, 4)


                If Me.txtID_CARD_ISSUE_DD.Text <> "" And Me.txtID_CARD_ISSUE_MM.Text <> "" And Me.txtID_CARD_ISSUE_DD.Text <> "" Then
                    Me.txtID_CARD_ISSUE_DATE_EN.Text = clsValid.ConcatDate(Me.txtID_CARD_ISSUE_DD.Text,
                                                    Me.txtID_CARD_ISSUE_MM.Text,
                                                    CInt(Me.txtID_CARD_ISSUE_YYYY.Text) - 543)
                End If


                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ระบบได้ชื่อและนามสกุลจาก Smart Card มาแสดง');", True)
            Else
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ไม่พบข้อมูลจาก Smart Card');", True)
            End If


        Catch ex As Exception
            Console.WriteLine("")

        End Try


    End Sub

    Protected Sub btnSearch_BO_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch_BO.Click
        Me.Find_Mcustomer_for_BO(Me.txtBO_uniqueID.Text)
    End Sub

    Protected Sub btnClear_BO_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClear_BO.Click
        Me.Clear_BO() : Me.txtBO_uniqueID.Focus()
    End Sub



    Sub Clear_Screen()
        Me.txtBO_FIRSTNAME_TH.Enabled = True
        Me.txtBO_MIDNAME_TH.Enabled = True
        Me.txtBO_LASTNAME_TH.Enabled = True
    End Sub
#End Region

    Protected Sub btnCHECK_List_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFilter_CUST.Click
        Try
            Session("chkKYC") = Nothing
            Dim lvsWhatIsThis As DataSet = Session("ds")
            If Not lvsWhatIsThis Is Nothing AndAlso lvsWhatIsThis.Tables("Result").Rows.Count > 0 Then
                lblRISK_LEVEL_CUST.Text = Me.hdfLevel.Value
                '''''''''''''''''''''''''''''''''''''''''''
                grdList.DataSource = lvsWhatIsThis.Tables("Result")
                grdList.DataBind()
                '''''''''''''''''''''''''''''''''''''''''''
            Else
                lblRISK_LEVEL_CUST.Text = 0
            End If

            If Session("Sanction") = Nothing Then
                Me.lblFILTER_RESULT_CUST.Text = "ไม่มีรายชื่อใน List"
                lblRISK_LEVEL_CUST.Text = 1
            Else
                Me.lblFILTER_RESULT_CUST.Text = "มีรายชื่อใน List"
            End If

            Session("Sanction") = Nothing

            '''''to find that Risk From Passport is highter than risk from IDcard or not'''''
            If CInt(lblCount_Passport.Text) > 0 Then
                Me.Find_Score_Passport()

                If CInt(lblRISK_LEVEL_PASSPORT.Text) > CInt(lblRISK_LEVEL_CUST.Text) Then
                    Me.lblFILTER_RESULT_CUST.Text = Me.lblFILTER_RESULT_PASSPORT.Text & "-P"
                    Me.lblRISK_LEVEL_CUST.Text = Me.lblRISK_LEVEL_PASSPORT.Text
                End If

            End If
            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

        Catch ex As Exception
            Console.WriteLine("")

        End Try
    End Sub

#Region "ผลิตภัณฑ์"

    Sub Bind_Data_togrid_Product()

        '''' Connect Data to Grid '''''''''''
        Me.dtProduct.Columns.Add("PRODUCTNAME")
        Me.dtProduct.Columns.Add("PRODUCTCODE")
        Me.dtProduct.Columns.Add("RISK")
        Me.dtProduct.Columns.Add("ACTIVE")

        Dim lvsCustType As Integer = Session("KYC")

        Dim QryProduct = (From tbName In KYCEntity.MCUST_PRODUCT
                        Where tbName.CUSTSEQ = CustSeq
                       Select tbName.SEQ,
                              tbName.PRODUCTNAME,
                              tbName.PRODUCTCODE,
                              tbName.RISK,
                              ACTIVE = If(tbName.ACTIVE = "Y", True, False)
                     Order By SEQ)

        For Each mRow In QryProduct
            Me.dtProduct.Rows.Add(mRow.PRODUCTNAME,
                                 mRow.PRODUCTCODE,
                                 mRow.RISK,
                                 mRow.ACTIVE)

            Me.dtProduct.AcceptChanges()
        Next

        Me.grdPRODUCT.DataSource = Me.dtProduct
        Me.grdPRODUCT.DataBind()
        ''''Number of Rows ''''''''''''''''''''''''''''''''''
        Me.lblCount_Product.Text = Me.dtProduct.Rows.Count
        '''''''''''''''''''''''''''''''''''''''''''''''''''''
        Session("PopProduct") = Me.dtProduct

    End Sub

    Protected Sub chk_ACT_PRODUCT_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)

        ''''check Session ''''''''''''''''''''''
        If Not (Session("PopProduct") Is Nothing) Then
            Me.dtProduct = Session("PopProduct")
        End If

        '''''' assign checkbox value to data table 
        For i = 0 To Me.grdPRODUCT.Rows.Count - 1
            Me.dtProduct.Rows(i).Item("ACTIVE") = CType(Me.grdPRODUCT.Rows(i).Cells(3).FindControl("chk_ACT_PRODUCT"), CheckBox).Checked
        Next i

        Me.dtProduct.AcceptChanges()
        Me.grdPRODUCT.DataSource = Me.dtProduct
        Me.grdPRODUCT.DataBind()

        Session("PopProduct") = Me.dtProduct
    End Sub

    Function Validate_Product() As Boolean
        Validate_Product = False

        ''''''''Validate ข้อมูลซ้ำ''''''''''''''''''
        Dim mProduct As String = ""
        For Each rowProduct As GridViewRow In grdPRODUCT.Rows
            mProduct = rowProduct.Cells(1).Text
            If mProduct = ddlPRODUCT_NAME.SelectedItem.Text Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ข้อมูลซ้ำ ! กรูณาเลือกผลิตภัณฑ์');", True)
                ddlPRODUCT_NAME.Focus()
                Exit Function
            End If

        Next
        '''''''''''''''''''''''''''''
        Validate_Product = True
    End Function

    Protected Sub btAddProduct_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btAddProduct.Click
        Add_To_grid_Product()
    End Sub

    Sub Add_To_grid_Product()

        If Validate_Product() = False Then Exit Sub

        'check session of data table
        If Not (Session("PopProduct") Is Nothing) Then
            Me.dtProduct = Session("PopProduct")
        End If

        '''''''' insert data to grid row '''''''''''''''''''''''''''''''''''''''''''''''''

        '''''''''''''
        Dim dtRisk_Level As DataTable = New DataTable
        Dim lvsRisk As Integer = 1

        lvsSQL = ""
        lvsSQL += "     SELECT RISK                                                         "
        lvsSQL += "       FROM KYCADMIN.MPRODUCT                                            "
        lvsSQL += "      WHERE PRODUCTCODE = '" & Me.ddlPRODUCT_NAME.SelectedItem.Value & "'"

        dtRisk_Level = clsDatabase.QueryDataTable(lvsSQL)

        If (dtRisk_Level.Rows.Count <> 0) Then
            If Not IsDBNull(dtRisk_Level.Rows(0)("RISK")) Then lvsRisk = dtRisk_Level.Rows(0)("RISK")
        End If
        ''''''''''

        dtProduct.Rows.Add(Me.ddlPRODUCT_NAME.SelectedItem,
                          Me.ddlPRODUCT_NAME.SelectedValue,
                          lvsRisk,
                          True)
        dtProduct.AcceptChanges()
        Me.grdPRODUCT.DataSource = dtProduct
        Me.grdPRODUCT.DataBind()
        ''''Number of Rows ''''''''''''''''''''''''''''''''''
        Me.lblCount_Product.Text = Me.dtProduct.Rows.Count
        '''''''''''''''''''''''''''''''''''''''''''''''''''''
        ''''deselect ''''''''''''''''''''' 
        Me.grdPRODUCT.SelectedIndex = -1
        ''''''''''''''''''''''''''''''''''
        '''''now bind datatable to gridview... 
        Session("PopProduct") = Me.dtProduct

        ''''Clear Screen'''''''''

        Me.ddlPRODUCT_NAME.Focus()
    End Sub

    Protected Sub btDelProduct_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btDelProduct.Click
        Me.Delete_gridRow_grdProduct()
    End Sub

    Sub Delete_gridRow_grdProduct()
        Try

            Dim index As Integer = grdProduct.SelectedIndex
            If index = -1 Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('ต้องเลือกผลิตภัณฑ์ที่ต้องการลบก่อน')", True)
            Else
                'check session of data table
                If Not (Session("PopProduct") Is Nothing) Then
                    Me.dtProduct = Session("PopProduct")
                End If
                ''''remove row at...
                dtProduct.Rows.RemoveAt(index)
                dtProduct.AcceptChanges()

                ''''bind data again
                grdProduct.DataSource = Me.dtProduct
                grdProduct.DataBind()
                ''''Number of Rows ''''''''''''''''''''''''''''''''''
                Me.lblCount_Product.Text = Me.dtProduct.Rows.Count
                '''''''''''''''''''''''''''''''''''''''''''''''''''''

                ''''deselect ''''''''''''''''
                grdProduct.SelectedIndex = -1
                '''''''''''''''''''''''''''''
            End If

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Page,
                                                Page.GetType(),
                                                "clientScript",
                                                "alert('" + ex.Message.Replace("'", "") + "')",
                                                True)
        End Try

    End Sub

    Protected Sub grdPRODUCT_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdPRODUCT.SelectedIndexChanged
        If grdPRODUCT.SelectedIndex = intBeforeSelectIndex_Product Then
            grdPRODUCT.SelectedIndex = -1
        End If
    End Sub

    Protected Sub grdPRODUCT_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles grdPRODUCT.SelectedIndexChanging
        Me.intBeforeSelectIndex_Product = grdPRODUCT.SelectedIndex
    End Sub

    Protected Sub Save_to_Cust_Product(ByVal key As Integer)

        Dim mProductName As String = ""
        Dim mProductCode As String = ""
        Dim mPrd_Risk As String = ""
        Dim chActive As String = ""
        Dim lvsCustType As Integer = Session("KYC")
        '''''''''''''''''''''''

        Try

            Dim DeletedQuery = (From m In KYCEntity.MCUST_PRODUCT
                               Where m.CUSTSEQ = key _
                              Select m).ToList

            If DeletedQuery.Count > 0 Then
                For i As Integer = 0 To DeletedQuery.Count - 1
                    KYCEntity.MCUST_PRODUCT.DeleteObject(DeletedQuery(i))
                Next i
            End If
            ''''''''''''''''''''''
            For Each rowID As GridViewRow In Me.grdPRODUCT.Rows
                Dim newCust_Product As New MCUST_PRODUCT

                ''''get values from Gridview '''''''
                mProductName = rowID.Cells(1).Text : If mProductName = "&nbsp;" Then mProductName = ""
                mProductCode = rowID.Cells(2).Text : If mProductCode = "&nbsp;" Then mProductCode = ""
                mPrd_Risk = rowID.Cells(3).Text : If mPrd_Risk = "&nbsp;" Then mPrd_Risk = ""

                If (CType(rowID.Cells(4).FindControl("chk_ACT_PRODUCT"), CheckBox).Checked = True) Then
                    chActive = "Y"
                Else
                    chActive = "N"
                End If


                ''''''''''''''''''''''''''''''''''''

                '''''''LINQ Start here ''''''''''''''
                newCust_Product.CUSTSEQ = key
                newCust_Product.CUSTTYPE = Session("KYC")
                newCust_Product.SEQ = rowID.RowIndex + 1
                newCust_Product.PRODUCTCODE = mProductCode
                newCust_Product.PRODUCTNAME = mProductName
                newCust_Product.RISK = mPRD_RISK
                newCust_Product.ACTIVE = chActive
                newCust_Product.CREATED_DATE = Now
                newCust_Product.CREATED_BY = clsSessionMenuRight.getUserName
                KYCEntity.AddToMCUST_PRODUCT(newCust_Product)
            Next
            KYCEntity.SaveChanges()
        Catch ex As Exception
            Throw ex
            'Catch ex As System.Data.SqlClient.SqlException
            '    Dim lvsERROR As String = ex.Message.ToString
            '    ScriptManager.RegisterStartupScript(Me, Me.GetType(), "clientScript", "alert('" & lvsERROR & "')", True)
        End Try



    End Sub


#End Region

#Region "บริการเสริม"

    Sub Bind_Data_togrdAddedService()

        '''' Connect Data to Grid '''''''''''
        Me.dtAddedService.Columns.Add("ADDEDSERVICENAME")
        Me.dtAddedService.Columns.Add("ADDEDSERVICECODE")
        Me.dtAddedService.Columns.Add("RISK")
        Me.dtAddedService.Columns.Add("ACTIVE")

        Dim lvsCustType As Integer = Session("KYC")

        Dim qryAddedService = (From tbName In KYCEntity.MCUST_ADDED_SERVICE
                        Where tbName.CUSTSEQ = CustSeq
                       Select tbName.SEQ,
                              tbName.ADDEDSERVICENAME,
                              tbName.ADDEDSERVICECODE,
                              tbName.RISK,
                              ACTIVE = If(tbName.ACTIVE = "Y", True, False)
                     Order By SEQ)

        For Each mRow In qryAddedService
            Me.dtAddedService.Rows.Add(mRow.ADDEDSERVICENAME,
                                 mRow.ADDEDSERVICECODE,
                                 mRow.RISK,
                                 mRow.ACTIVE)

            Me.dtAddedService.AcceptChanges()
        Next

        Me.grdAddedService.DataSource = Me.dtAddedService
        Me.grdAddedService.DataBind()
        ''''Number of Rows ''''''''''''''''''''''''''''''''''
        Me.lblCount_AddedService.Text = Me.dtAddedService.Rows.Count
        '''''''''''''''''''''''''''''''''''''''''''''''''''''
        Session("PopAddedService") = Me.dtAddedService

    End Sub

    Protected Sub chk_ACT_ADDEDSERVICE_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)

        ''''check Session ''''''''''''''''''''''
        If Not (Session("PopAddedService") Is Nothing) Then
            Me.dtAddedService = Session("PopAddedService")
        End If

        '''''' assign checkbox value to data table 
        For i = 0 To Me.grdAddedService.Rows.Count - 1
            Me.dtAddedService.Rows(i).Item("ACTIVE") = CType(Me.grdAddedService.Rows(i).Cells(3).FindControl("chk_ACT_ADDEDSERVICE"), CheckBox).Checked
        Next i

        Me.dtAddedService.AcceptChanges()
        Me.grdAddedService.DataSource = Me.dtAddedService
        Me.grdAddedService.DataBind()

        Session("PopAddedService") = Me.dtAddedService
    End Sub

    Function Validate_AddedService() As Boolean
        Validate_AddedService = False

        ''''''''Validate ข้อมูลซ้ำ''''''''''''''''''
        Dim mProduct As String = ""
        For Each rowProduct As GridViewRow In grdAddedService.Rows
            mProduct = rowProduct.Cells(1).Text
            If mProduct = ddlADDED_SERVICE.SelectedItem.Text Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ข้อมูลซ้ำ ! กรูณาเลือกบริการเสริมอื่น');", True)
                ddlADDED_SERVICE.Focus()
                Exit Function
            End If

        Next
        '''''''''''''''''''''''''''''
        Validate_AddedService = True
    End Function

    Protected Sub btAdd_ADDEDSERVICE_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btAdd_ADDEDSERVICE.Click
        Add_To_grdAddedService()
    End Sub

    Sub Add_To_grdAddedService()

        If Validate_AddedService() = False Then Exit Sub

        'check session of data table
        If Not (Session("PopAddedService") Is Nothing) Then
            Me.dtAddedService = Session("PopAddedService")
        End If

        '''''''' insert data to grid row '''''''''''''''''''''''''''''''''''''''''''''''''

        '''''''''''''
        Dim dtRisk_Level As DataTable = New DataTable
        Dim lvsRisk As Integer = 1

        lvsSQL = ""
        lvsSQL += "     SELECT RISK                                                             "
        lvsSQL += "       FROM KYCADMIN.MADDITION_SERVICE                                       "
        lvsSQL += "      WHERE ADSERVICECODE = '" & Me.ddlADDED_SERVICE.SelectedItem.Value & "'  "

        dtRisk_Level = clsDatabase.QueryDataTable(lvsSQL)

        If (dtRisk_Level.Rows.Count <> 0) Then
            If Not IsDBNull(dtRisk_Level.Rows(0)("RISK")) Then lvsRisk = dtRisk_Level.Rows(0)("RISK")
        End If
        ''''''''''
        dtAddedService.Rows.Add(Me.ddlADDED_SERVICE.SelectedItem,
                          Me.ddlADDED_SERVICE.SelectedValue,
                          lvsRisk,
                          True)
        dtAddedService.AcceptChanges()
        Me.grdAddedService.DataSource = dtAddedService
        Me.grdAddedService.DataBind()
        ''''Number of Rows ''''''''''''''''''''''''''''''''''
        Me.lblCount_AddedService.Text = Me.dtAddedService.Rows.Count
        '''''''''''''''''''''''''''''''''''''''''''''''''''''
        ''''deselect ''''''''''''''''''''' 
        Me.grdAddedService.SelectedIndex = -1
        ''''''''''''''''''''''''''''''''''
        '''''now bind datatable to gridview... 
        Session("PopAddedService") = Me.dtAddedService

        ''''Clear Screen'''''''''

        Me.ddlADDED_SERVICE.Focus()
    End Sub

    Protected Sub btDelAddedService_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btDelAddedService.Click
        Me.Delete_gridRow_grdAddedService()
    End Sub

    Sub Delete_gridRow_grdAddedService()
        Try

            Dim index As Integer = grdAddedService.SelectedIndex
            If index = -1 Then
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('ต้องเลือกบริการเสริมที่ต้องการลบก่อน')", True)
            Else
                'check session of data table
                If Not (Session("PopAddedService") Is Nothing) Then
                    Me.dtAddedService = Session("PopAddedService")
                End If
                ''''remove row at...
                dtAddedService.Rows.RemoveAt(index)
                dtAddedService.AcceptChanges()

                ''''bind data again
                grdAddedService.DataSource = Me.dtAddedService
                grdAddedService.DataBind()
                ''''Number of Rows ''''''''''''''''''''''''''''''''''
                Me.lblCount_AddedService.Text = Me.dtAddedService.Rows.Count
                '''''''''''''''''''''''''''''''''''''''''''''''''''''

                ''''deselect ''''''''''''''''
                grdAddedService.SelectedIndex = -1
                '''''''''''''''''''''''''''''
            End If

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Page,
                                                Page.GetType(),
                                                "clientScript",
                                                "alert('" + ex.Message.Replace("'", "") + "')",
                                                True)
        End Try

    End Sub

    Protected Sub grdAddedService_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdAddedService.SelectedIndexChanged
        If grdAddedService.SelectedIndex = intBeforeSelectIndex_AddedService Then
            grdAddedService.SelectedIndex = -1
        End If
    End Sub

    Protected Sub grdAddedService_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles grdAddedService.SelectedIndexChanging
        Me.intBeforeSelectIndex_AddedService = grdAddedService.SelectedIndex
    End Sub

    Protected Sub Save_to_Cust_AddedService(ByVal key As Integer)

        Dim mADDEDSERVICENAME As String = ""
        Dim mADDEDSERVICECODE As String = ""
        Dim mADDEDSERV_RISK As String = ""
        Dim chActive As String = ""
        Dim lvsCustType As Integer = Session("KYC")
        '''''''''''''''''''''''

        Try

            Dim DeletedQuery = (From m In KYCEntity.MCUST_ADDED_SERVICE
                               Where m.CUSTSEQ = key _
                              Select m).ToList

            If DeletedQuery.Count > 0 Then
                For i As Integer = 0 To DeletedQuery.Count - 1
                    KYCEntity.MCUST_ADDED_SERVICE.DeleteObject(DeletedQuery(i))
                Next i
            End If
            ''''''''''''''''''''''
            For Each rowAddedService As GridViewRow In Me.grdAddedService.Rows
                Dim newCust_AddedService As New MCUST_ADDED_SERVICE

                ''''get values from Gridview '''''''
                mADDEDSERVICENAME = rowAddedService.Cells(1).Text : If mADDEDSERVICENAME = "&nbsp;" Then mADDEDSERVICENAME = ""
                mADDEDSERVICECODE = rowAddedService.Cells(2).Text : If mADDEDSERVICECODE = "&nbsp;" Then mADDEDSERVICECODE = ""
                mADDEDSERV_RISK = rowAddedService.Cells(3).Text : If mADDEDSERV_RISK = "&nbsp;" Then mADDEDSERV_RISK = ""

                If (CType(rowAddedService.Cells(4).FindControl("chk_ACT_ADDEDSERVICE"), CheckBox).Checked = True) Then
                    chActive = "Y"
                Else
                    chActive = "N"
                End If


                ''''''''''''''''''''''''''''''''''''

                '''''''LINQ Start here ''''''''''''''
                newCust_AddedService.CUSTSEQ = key
                newCust_AddedService.CUSTTYPE = Session("KYC")
                newCust_AddedService.SEQ = rowAddedService.RowIndex + 1
                newCust_AddedService.ADDEDSERVICECODE = mADDEDSERVICECODE
                newCust_AddedService.ADDEDSERVICENAME = mADDEDSERVICENAME
                newCust_AddedService.RISK = mADDEDSERV_RISK
                newCust_AddedService.ACTIVE = chActive
                newCust_AddedService.CREATED_DATE = Now
                newCust_AddedService.CREATED_BY = clsSessionMenuRight.getUserName
                KYCEntity.AddToMCUST_ADDED_SERVICE(newCust_AddedService)
            Next
            KYCEntity.SaveChanges()
        Catch ex As Exception
            Throw ex
            'Catch ex As System.Data.SqlClient.SqlException
            '    Dim lvsERROR As String = ex.Message.ToString
            '    ScriptManager.RegisterStartupScript(Me, Me.GetType(), "clientScript", "alert('" & lvsERROR & "')", True)
        End Try

    End Sub

#End Region

    Protected Sub chkCustDeny_to_give_information_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkCustDeny_to_give_information.CheckedChanged
        If chkCustDeny_to_give_information.Checked = True Then
            Me.Set_Family_Enable_False()
        Else
            Me.Set_Family_Enable_True()
        End If
    End Sub



#Region "Function"

    Public Function Gen_CusSeq(ByVal lvsRow_No As Integer) As Integer

        Try

            Dim dtCustSEQ As DataTable = New DataTable
            Dim lvsCustSeq As Integer

            dtCustSEQ = Nothing

            lvsSQL = ""
            lvsSQL += "     SELECT MAX (CUSTSEQ) + '" & lvsRow_No & "' AS CUSTSEQ     "
            lvsSQL += "       FROM KYCADMIN.MCUSTOMER               "
            dtCustSEQ = clsDatabase.QueryDataTable(lvsSQL)

            If (dtCustSEQ.Rows.Count <> 0) Then
                lvsCustSeq = dtCustSEQ.Rows(0)("CUSTSEQ")
            End If


            Return lvsCustSeq

        Catch ex As Exception
            Console.WriteLine("")

        End Try

    End Function


#End Region

    Protected Sub ddlPrefixTH_POLITIC_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlPrefixTH_POLITIC.SelectedIndexChanged
        Me.ddlPrefixEN_POLITIC.SelectedValue = Me.ddlPrefixTH_POLITIC.SelectedValue
    End Sub

    Protected Sub ddlPrefixEN_POLITIC_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlPrefixEN_POLITIC.SelectedIndexChanged
        Me.ddlPrefixTH_POLITIC.SelectedValue = Me.ddlPrefixEN_POLITIC.SelectedValue
    End Sub

    Protected Sub ddlPrefixTH_BO_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlPrefixTH_BO.SelectedIndexChanged
        Me.ddlPrefixEN_BO.SelectedValue = Me.ddlPrefixTH_BO.SelectedValue
    End Sub

    Protected Sub ddlPrefixEN_BO_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlPrefixEN_BO.SelectedIndexChanged
        Me.ddlPrefixTH_BO.SelectedValue = Me.ddlPrefixEN_BO.SelectedValue
    End Sub

    Protected Sub ddlPrefixTH_Fam_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlPrefixTH_FAM.SelectedIndexChanged
        Me.ddlPrefixEN_FAM.SelectedValue = Me.ddlPrefixTH_FAM.SelectedValue
    End Sub

    Protected Sub ddlPrefixEN_Fam_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlPrefixEN_FAM.SelectedIndexChanged
        Me.ddlPrefixTH_FAM.SelectedValue = Me.ddlPrefixEN_FAM.SelectedValue
    End Sub

    Protected Sub btnSearch_FAM_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch_FAM.Click
        Me.Find_Mcustomer_for_FAM(Me.txtFAM_UNIQUEID.Text)
    End Sub

#Region ""

    Sub Find_Mcustomer_for_FAM(ByVal Citizen_ID As String)

        Try

            If Me.Validate_ID_CARD(Me.txtFAM_UNIQUEID) = False Then Exit Sub


            Dim dtSmartCard As DataTable = New DataTable


            Me.txtFAM_FIRSTNAME_TH.Text = ""
            Me.txtFAM_MIDNAME_TH.Text = ""
            Me.txtFAM_LASTNAME_TH.Text = ""

            Me.txtFAM_FIRSTNAME_EN.Text = ""
            Me.txtFAM_MIDNAME_EN.Text = ""
            Me.txtFAM_LASTNAME_EN.Text = ""

            lvsSQL = ""
            lvsSQL += "      SELECT THFIRSTNAME,                        "
            lvsSQL += "             THMIDNAME,                          "
            lvsSQL += "             THLASTNAME,                         "
            lvsSQL += "             THPREFIX,                           "
            lvsSQL += "             ENFIRSTNAME,                        "
            lvsSQL += "             ENMIDNAME,                          "
            lvsSQL += "             ENLASTNAME,                         "
            lvsSQL += "             ENPREFIX                            "
            lvsSQL += "        FROM MCUSTOMER                           "
            lvsSQL += "       WHERE UNIQUEID = '" & Citizen_ID & "'     "
            dtSmartCard = clsDatabase.QueryDataTable(lvsSQL)

            If (dtSmartCard.Rows.Count <> 0) Then
                If Not IsDBNull(dtSmartCard.Rows(0)("THPREFIX")) Then Me.ddlPrefixTH_FAM.SelectedValue = dtSmartCard.Rows(0)("THPREFIX")
                If Not IsDBNull(dtSmartCard.Rows(0)("THFIRSTNAME")) Then Me.txtFAM_FIRSTNAME_TH.Text = dtSmartCard.Rows(0)("THFIRSTNAME")
                If Not IsDBNull(dtSmartCard.Rows(0)("THMIDNAME")) Then Me.txtFAM_MIDNAME_TH.Text = dtSmartCard.Rows(0)("THMIDNAME")
                If Not IsDBNull(dtSmartCard.Rows(0)("THLASTNAME")) Then Me.txtFAM_LASTNAME_TH.Text = dtSmartCard.Rows(0)("THLASTNAME")

                If Not IsDBNull(dtSmartCard.Rows(0)("ENPREFIX")) Then Me.ddlPrefixEN_FAM.SelectedValue = dtSmartCard.Rows(0)("ENPREFIX")
                If Not IsDBNull(dtSmartCard.Rows(0)("ENFIRSTNAME")) Then Me.txtFAM_FIRSTNAME_EN.Text = dtSmartCard.Rows(0)("ENFIRSTNAME")
                If Not IsDBNull(dtSmartCard.Rows(0)("ENMIDNAME")) Then Me.txtFAM_MIDNAME_EN.Text = dtSmartCard.Rows(0)("ENMIDNAME")
                If Not IsDBNull(dtSmartCard.Rows(0)("ENLASTNAME")) Then Me.txtFAM_LASTNAME_EN.Text = dtSmartCard.Rows(0)("ENLASTNAME")

                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ระบบได้ชื่อและนามสกุลจากระบบ KYC มาแสดง');", True)
            Else
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ไม่พบข้อมูลจากระบบ KYC ระบบจะค้นหาข้อมููลจากระบบ Smart Card');", True)
                Me.Find_SmartCard_for_FAM(Me.txtFAM_UNIQUEID.Text)
            End If


        Catch ex As Exception
            '  Console.WriteLine("")
            ScriptManager.RegisterStartupScript(Page, Page.GetType(),
                                    "clientScript",
                                    "alert('" + ex.Message.Replace("'", "") + "')",
                                    True)

        End Try

    End Sub


    Sub Find_SmartCard_for_FAM(ByVal Citizen_ID As String)

        Try

            If Me.Validate_ID_CARD(Me.txtFAM_UNIQUEID) = False Then Exit Sub


            Dim dtSmartCard As DataTable = New DataTable

            lvsSQL = ""
            lvsSQL += "     SELECT FIRST_NAME,                          "
            lvsSQL += "            LAST_NAME,                           "
            lvsSQL += "            FIRST_NAME_EN,                       "
            lvsSQL += "            LAST_NAME_EN,                        "
            lvsSQL += "            BIRTH_DATE,                          "
            lvsSQL += "            START_DATE                           "
            lvsSQL += "       FROM KYCADMIN.GHB_BORAINTERFACE           "
            lvsSQL += "      WHERE CITIZEN_ID = '" & Citizen_ID & "'    "
            dtSmartCard = clsDatabase.QueryDataTable(lvsSQL)

            If (dtSmartCard.Rows.Count <> 0) Then

                If Not IsDBNull(dtSmartCard.Rows(0)("FIRST_NAME")) Then Me.txtFAM_FIRSTNAME_TH.Text = dtSmartCard.Rows(0)("FIRST_NAME")
                If Not IsDBNull(dtSmartCard.Rows(0)("LAST_NAME")) Then Me.txtFAM_LASTNAME_TH.Text = dtSmartCard.Rows(0)("LAST_NAME")
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ระบบได้ชื่อและนามสกุลจากระบบ Smart Card มาแสดง');", True)
            Else
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ไม่พบข้อมูลจาก Smart Card');", True)
                Me.ddlPrefixTH_FAM.Focus()
            End If


        Catch ex As Exception
            '  Console.WriteLine("")
            ScriptManager.RegisterStartupScript(Page, Page.GetType(),
                                    "clientScript",
                                    "alert('" + ex.Message.Replace("'", "") + "')",
                                    True)

        End Try

    End Sub

    Protected Sub btnClear_FAM_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClear_FAM.Click
        Clear_FAM()
    End Sub

    Sub Clear_FAM()
        Me.ddlPrefixTH_FAM.SelectedIndex = -1
        Me.ddlPrefixEN_FAM.SelectedIndex = -1
        Me.txtFAM_CIF_NO.Text = ""
        Me.txtFAM_UNIQUEID.Text = ""
        Me.txtFAM_PASSPORT_NO.Text = ""
        Me.txtFAM_FIRSTNAME_TH.Text = ""
        Me.txtFAM_LASTNAME_TH.Text = ""
        Me.txtFAM_MIDNAME_TH.Text = ""
        Me.txtFAM_FIRSTNAME_EN.Text = ""
        Me.txtFAM_LASTNAME_EN.Text = ""
        Me.txtFAM_MIDNAME_EN.Text = ""
    End Sub

    Sub Find_Mcustomer_for_BO(ByVal Citizen_ID As String)

        Try

            If Me.Validate_ID_CARD(Me.txtBO_uniqueID) = False Then Exit Sub

            Dim dtSmartCard As DataTable = New DataTable

            Me.txtBO_FIRSTNAME_TH.Text = ""
            Me.txtBO_MIDNAME_TH.Text = ""
            Me.txtBO_LASTNAME_TH.Text = ""

            Me.txtBO_FIRSTNAME_EN.Text = ""
            Me.txtBO_MIDNAME_EN.Text = ""
            Me.txtBO_LASTNAME_EN.Text = ""

            lvsSQL = ""
            lvsSQL += "      SELECT THFIRSTNAME,                        "
            lvsSQL += "             THMIDNAME,                          "
            lvsSQL += "             THLASTNAME,                         "
            lvsSQL += "             THPREFIX,                           "
            lvsSQL += "             ENFIRSTNAME,                        "
            lvsSQL += "             ENMIDNAME,                          "
            lvsSQL += "             ENLASTNAME,                         "
            lvsSQL += "             ENPREFIX                            "
            lvsSQL += "        FROM MCUSTOMER                           "
            lvsSQL += "       WHERE UNIQUEID = '" & Citizen_ID & "'     "
            dtSmartCard = clsDatabase.QueryDataTable(lvsSQL)

            If (dtSmartCard.Rows.Count <> 0) Then
                If Not IsDBNull(dtSmartCard.Rows(0)("THPREFIX")) Then Me.ddlPrefixTH_BO.SelectedValue = dtSmartCard.Rows(0)("THPREFIX")
                If Not IsDBNull(dtSmartCard.Rows(0)("THFIRSTNAME")) Then Me.txtBO_FIRSTNAME_TH.Text = dtSmartCard.Rows(0)("THFIRSTNAME")
                If Not IsDBNull(dtSmartCard.Rows(0)("THMIDNAME")) Then Me.txtBO_MIDNAME_TH.Text = dtSmartCard.Rows(0)("THMIDNAME")
                If Not IsDBNull(dtSmartCard.Rows(0)("THLASTNAME")) Then Me.txtBO_LASTNAME_TH.Text = dtSmartCard.Rows(0)("THLASTNAME")

                If Not IsDBNull(dtSmartCard.Rows(0)("ENPREFIX")) Then Me.ddlPrefixEN_BO.SelectedValue = dtSmartCard.Rows(0)("ENPREFIX")
                If Not IsDBNull(dtSmartCard.Rows(0)("ENFIRSTNAME")) Then Me.txtBO_FIRSTNAME_EN.Text = dtSmartCard.Rows(0)("ENFIRSTNAME")
                If Not IsDBNull(dtSmartCard.Rows(0)("ENMIDNAME")) Then Me.txtBO_MIDNAME_EN.Text = dtSmartCard.Rows(0)("ENMIDNAME")
                If Not IsDBNull(dtSmartCard.Rows(0)("ENLASTNAME")) Then Me.txtBO_LASTNAME_EN.Text = dtSmartCard.Rows(0)("ENLASTNAME")

                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ระบบได้ชื่อและนามสกุลจากระบบ KYC มาแสดง');", True)
            Else
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ไม่พบข้อมูลจากระบบ KYC ระบบจะค้นหาข้อมููลจากระบบ Smart Card');", True)
                Me.Find_SmartCard_for_BO(Me.txtBO_uniqueID.Text)
            End If


        Catch ex As Exception
            '  Console.WriteLine("")
            ScriptManager.RegisterStartupScript(Page, Page.GetType(),
                                    "clientScript",
                                    "alert('" + ex.Message.Replace("'", "") + "')",
                                    True)

        End Try

    End Sub

    Sub Find_SmartCard_for_BO(ByVal Citizen_ID As String)

        Try

            If Me.Validate_ID_CARD(Me.txtBO_uniqueID) = False Then Exit Sub


            Dim dtSmartCard As DataTable = New DataTable

            lvsSQL = ""
            lvsSQL += "     SELECT FIRST_NAME,                          "
            lvsSQL += "            LAST_NAME,                           "
            lvsSQL += "            FIRST_NAME_EN,                       "
            lvsSQL += "            LAST_NAME_EN,                        "
            lvsSQL += "            BIRTH_DATE,                          "
            lvsSQL += "            START_DATE                           "
            lvsSQL += "       FROM KYCADMIN.GHB_BORAINTERFACE           "
            lvsSQL += "      WHERE CITIZEN_ID = '" & Citizen_ID & "'    "
            dtSmartCard = clsDatabase.QueryDataTable(lvsSQL)

            If (dtSmartCard.Rows.Count <> 0) Then

                If Not IsDBNull(dtSmartCard.Rows(0)("FIRST_NAME")) Then Me.txtBO_FIRSTNAME_TH.Text = dtSmartCard.Rows(0)("FIRST_NAME")
                If Not IsDBNull(dtSmartCard.Rows(0)("LAST_NAME")) Then Me.txtBO_LASTNAME_TH.Text = dtSmartCard.Rows(0)("LAST_NAME")

                If Not IsDBNull(dtSmartCard.Rows(0)("FIRST_NAME_EN")) Then Me.txtBO_FIRSTNAME_EN.Text = dtSmartCard.Rows(0)("FIRST_NAME_EN")
                If Not IsDBNull(dtSmartCard.Rows(0)("LAST_NAME_EN")) Then Me.txtBO_LASTNAME_EN.Text = dtSmartCard.Rows(0)("LAST_NAME_EN")

                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ระบบได้ชื่อและนามสกุลจากระบบ Smart Card มาแสดง');", True)
            Else
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ไม่พบข้อมูลจาก Smart Card');", True)
                Me.ddlPrefixTH_BO.Focus()
            End If


        Catch ex As Exception
            '  Console.WriteLine("")
            ScriptManager.RegisterStartupScript(Page, Page.GetType(),
                                    "clientScript",
                                    "alert('" + ex.Message.Replace("'", "") + "')",
                                    True)

        End Try

    End Sub
#End Region

    '#Region "Effect Grid"

    '    Private Sub FristRowOccDetail()
    '        If grdOcc.Rows.Count > 0 Then
    '            ddlOccupation1.SelectedValue = CheckNSBP(grdOcc.Rows(0).Cells(2).Text.Trim)
    '            txtOccOther1.Text = CheckNSBP(grdOcc.Rows(0).Cells(4).Text.Trim)
    '            Dim clsDropDown As New clsMasterDropDown
    '            clsDropDown.setOccupation_4(ddlOccupation4, OccCode:=ddlOccupation1.SelectedValue)
    '            ddlOccupation4.SelectedValue = CheckNSBP(grdOcc.Rows(0).Cells(5).Text.Trim)
    '        Else
    '            txtPOSITION.Text = String.Empty
    '            txtOccOther1.Text = String.Empty
    '            txtBizOther1.Text = String.Empty
    '        End If

    '    End Sub

    '    Public Function CheckNSBP(ByVal sin As String) As String
    '        If (sin.Trim = "&nbsp;") Then
    '            Return ""
    '        End If
    '        Return sin
    '    End Function

    '#End Region

#Region "Set ReadOnly"
    Private Sub SetControl_Enable()
        Dim kyc = Request.QueryString("KYC")
        If kyc = 1 Then
            Me.txtCIF_FDR_NO.ReadOnly = True : Me.txtCIF_FDR_NO.BackColor = Drawing.Color.Silver
            Me.txtCIF_NPA_NO.ReadOnly = True : Me.txtCIF_NPA_NO.BackColor = Drawing.Color.Silver
        Else
            Me.txtCIF_FDR_NO.ReadOnly = False : Me.txtCIF_FDR_NO.BackColor = Drawing.Color.White
            Me.txtCIF_NPA_NO.ReadOnly = False : Me.txtCIF_NPA_NO.BackColor = Drawing.Color.White
        End If
    End Sub
#End Region

#Region "ประเมินความเสี่ยง"

    Protected Sub btnFind_Higthest_Score_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFind_Higthest_Score.Click
        Me.FindHeighest_Score_All()
    End Sub

    Sub FindHeighest_Score_All()

        If Me.lblFILTER_RESULT_CUST.Text = "" Then
            btnFilter_CUST.Focus()
            Exit Sub
        End If

        ''''clear Screen ''''''''''''''''''''''
        Me.lblEVAL_Sanct_list.Text = ""
        Me.lblEVAL_Sanct_Score.Text = ""

        Me.lblEVAL_INC_SOURCE.Text = ""
        Me.lblEVAL_INC_SOURCE_SCORE.Text = ""

        'Me.lblEAL_Sanct_list.Text = ""
        'Me.lblEVALSanct_Score.Text = ""

        'Me.lblEAL_Sanct_list.Text = ""
        'Me.lblEVALSanct_Score.Text = ""

        'Me.lblEAL_Sanct_list.Text = ""
        'Me.lblEVALSanct_Score.Text = ""

        '''''to find that Risk From Passport is highter than risk from IDcard or not'''''
        If CInt(lblCount_Passport.Text) > 0 Then
            Me.Find_Score_Passport()

            If CInt(lblRISK_LEVEL_PASSPORT.Text) > CInt(lblRISK_LEVEL_CUST.Text) Then
                Me.lblFILTER_RESULT_CUST.Text = Me.lblFILTER_RESULT_PASSPORT.Text
                Me.lblRISK_LEVEL_CUST.Text = Me.lblRISK_LEVEL_PASSPORT.Text
            End If

        End If
        '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

        Me.lblEVAL_Sanct_list.Text = Me.lblFILTER_RESULT_CUST.Text
        Me.lblEVAL_Sanct_Score.Text = Me.lblRISK_LEVEL_CUST.Text
        Me.Find_Score_BO()
        Me.Find_Score_Nation()
        Me.Find_Score_Inc_Source()
        Me.Find_Score_Occupation()
        Me.Find_Score_Added_Service()
        Me.Find_Score_Added_Product()
        Me.Find_Score_Residence()

    End Sub

    Sub Find_Score_Residence()

        Dim dtRisk_Level As DataTable = New DataTable

        lvsSQL = ""
        lvsSQL += "     SELECT NATIONALITYNAME,             "
        lvsSQL += "            RISK                         "
        lvsSQL += "       FROM KYCADMIN.MNATIONALITY        "
        lvsSQL += "      WHERE NATIONCODE = '202'           "
        dtRisk_Level = clsDatabase.QueryDataTable(lvsSQL)

        If (dtRisk_Level.Rows.Count <> 0) Then
            If Not IsDBNull(dtRisk_Level.Rows(0)("NATIONALITYNAME")) Then Me.lblEVAL_RESIDENT.Text = dtRisk_Level.Rows(0)("NATIONALITYNAME")
            If Not IsDBNull(dtRisk_Level.Rows(0)("RISK")) Then Me.lblEVAL_RESIDENT_SCORE.Text = dtRisk_Level.Rows(0)("RISK")
        End If
    End Sub


    Sub Find_Score_Passport()
        Try
            Dim dt As DataTable
            Dim err As String
            dt = GridviewToDataTable(Me.grdPassport, "5", err)

            Dim dataView As New DataView(dt)
            dataView.Sort = "5 Desc"  '3 Is Risk Score Column
            dt = dataView.ToTable()

            Dim RiskName As String = dt.Rows(0)("4").ToString()
            Dim RiskScore As String = dt.Rows(0)("5").ToString()

            Me.lblFILTER_RESULT_PASSPORT.Text = Mid(RiskName, 1, 20)
            Me.lblRISK_LEVEL_PASSPORT.Text = RiskScore

        Catch ex As Exception

        End Try
    End Sub

    Sub Find_Score_Added_Product()
        Try
            Dim dt As DataTable
            Dim err As String
            dt = GridviewToDataTable(Me.grdPRODUCT, "3", err)

            Dim dataView As New DataView(dt)
            dataView.Sort = "3 Desc"  '3 Is Risk Score Column
            dt = dataView.ToTable()

            Dim RiskName As String = dt.Rows(0)("1").ToString()
            Dim RiskScore As String = dt.Rows(0)("3").ToString()

            Me.lblEVAL_PRODUCT.Text = Mid(RiskName, 1, 20)
            Me.lblEVAL_PRODUCT_SCORE.Text = RiskScore

        Catch ex As Exception

        End Try
    End Sub

    Sub Find_Score_Added_Service()
        Try
            Dim dt As DataTable
            Dim err As String
            dt = GridviewToDataTable(Me.grdAddedService, "3", err)

            Dim dataView As New DataView(dt)
            dataView.Sort = "3 Desc"  '3 Is Risk Score Column
            dt = dataView.ToTable()

            Dim RiskName As String = dt.Rows(0)("1").ToString()
            Dim RiskScore As String = dt.Rows(0)("3").ToString()


            Me.lblEVAL_ADD_SERV.Text = Mid(RiskName, 1, 20)
            Me.lblEVAL_ADD_SERV_SCORE.Text = RiskScore

        Catch ex As Exception

        End Try
    End Sub

    Sub Find_Score_Occupation()
        Try
            Dim dt As DataTable
            Dim err As String
            dt = GridviewToDataTable(Me.grdOcc, "7", err)

            Dim dataView As New DataView(dt)
            dataView.Sort = "7 Desc"  '3 Is Risk Score Column
            dt = dataView.ToTable()

            Dim RiskName As String = dt.Rows(0)("3").ToString()
            Dim RiskScore As String = dt.Rows(0)("7").ToString()


            Me.lblEVAL_OCC.Text = Mid(RiskName, 1, 20)
            Me.lblEVAL_OCC_SCORE.Text = RiskScore

        Catch ex As Exception

        End Try
    End Sub

    Sub Find_Score_Inc_Source()
        Try
            Dim dt As DataTable
            Dim err As String
            dt = GridviewToDataTable(grdIncome, "4", err)

            Dim dataView As New DataView(dt)
            dataView.Sort = "4 Desc"  '3 Is Risk Score Column
            dt = dataView.ToTable()

            Dim RiskName As String = dt.Rows(0)("1").ToString()
            Dim RiskScore As String = dt.Rows(0)("4").ToString()

            Me.lblEVAL_INC_SOURCE.Text = Mid(RiskName, 1, 20)
            Me.lblEVAL_INC_SOURCE_SCORE.Text = RiskScore

        Catch ex As Exception

        End Try
    End Sub

    Sub Find_Score_BO()
        Try
            Dim dt As DataTable
            Dim err As String
            dt = GridviewToDataTable(grdBo, "19", err)

            Dim dataView As New DataView(dt)
            dataView.Sort = "19 Desc"  '3 Is Risk Score Column
            dt = dataView.ToTable()

            Dim RiskName As String = dt.Rows(0)("2").ToString()
            Dim RiskScore As String = dt.Rows(0)("19").ToString()

            Me.lblEVAL_Sanct_list_BO.Text = Mid(RiskName, 1, 20)
            Me.lblEVAL_Sanct_Score_BO.Text = RiskScore

        Catch ex As Exception

        End Try
    End Sub
    Sub Find_Score_Nation()
        Try
            Dim dt As DataTable
            Dim err As String
            dt = GridviewToDataTable(grdNaiton, "3", err)

            Dim dataView As New DataView(dt)
            dataView.Sort = "3 Desc"  '3 Is Risk Score Column
            dt = dataView.ToTable()

            Dim RiskName As String = dt.Rows(0)("1").ToString()
            Dim RiskScore As String = dt.Rows(0)("3").ToString()

            Me.lblEVAL_NATION.Text = Mid(RiskName, 1, 20)
            Me.lblEVAL_NATION_SCORE.Text = RiskScore

        Catch ex As Exception

        End Try
    End Sub

    Public Shared Function GridviewToDataTable(ByVal PassedGridView As GridView, ByVal lvscol As String, ByRef Error_Message As String) As DataTable
        '-----------------------------------------------
        'Dim Tbl_StackSheets = New Data.DataTable
        'Tbl_StackSheets = ReportsCommonClass.GridviewToDataTable(StackSheetsGridView)

        '-----------------------------------------------

        Dim dt As New DataTable
        Dim ColInd As Integer = 0
        Dim ValOffset As Integer
        Dim ColCount As Integer = 0

        Try

            For Each col As DataControlField In PassedGridView.Columns
                If lvscol = ColCount Then
                    dt.Columns.Add(ColCount.ToString(), GetType(Int32))
                Else
                    dt.Columns.Add(ColCount.ToString())
                End If
                ColCount += 1
            Next

            If (PassedGridView.AutoGenerateDeleteButton Or PassedGridView.AutoGenerateEditButton Or PassedGridView.AutoGenerateSelectButton) Then
                ValOffset = 1
            Else
                ValOffset = 0
            End If

            For Each row As GridViewRow In PassedGridView.Rows
                Dim NewDataRow As DataRow = dt.NewRow

                ColInd = 0
                For Each col As DataControlField In PassedGridView.Columns
                    NewDataRow(ColInd) = row.Cells(ColInd + ValOffset).Text.Replace("&nbsp;", "")
                    ColInd += 1
                Next

                dt.Rows.Add(NewDataRow)
            Next

            Error_Message = Nothing

        Catch ex As Exception
            Error_Message = "GridviewToDataTable: " & ex.Message
        End Try


        Return dt


    End Function

#End Region



   
 
End Class



